Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'createFromResource'

Tags:

android

I'm completely confused as to what this means. Ive done some searching but so far havent found any help.

I'm using android studio and have a dialog fragment I'm setting up a spinner in

 Spinner systemFontSpinner = (Spinner) view.findViewById(R.id.system_font_spinner);
 ArrayAdapter<String> arrayAdapter = new ArrayAdapter.createFromResource(getActivity(),
            R.array.system_fonts, android.R.layout.simple_spinner_dropdown_item);
 arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
 systemFontSpinner.setAdapter(arrayAdapter);

createFromResource is highlited in red and when I hover it it says "Cannot resolve symbol 'createFromResource'"

my array

<resources>
<string-array name="system_fonts">
    <item>Helvetica</item>
    <item>Helvetica-Neue</item>
    <item>Impact</item>
</string-array>
</resources>

my layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/system_font"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp" />

<Spinner
    android:id="@+id/system_font_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"/>

Any help would be greatly appreciated, thanks!

like image 583
Daniel H Avatar asked Apr 20 '26 11:04

Daniel H


1 Answers

Just so Spidy don't take all the glory :)

You're calling a static method that will return you an arrayadapter so you shouldn't be using new because you're not instantiating anything.

You should be doing it this way:

ArrayAdapter<String> arrayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.system_fonts, android.R.layout.simple_spinner_dropdown_item);

For reference: http://developer.android.com/reference/android/widget/ArrayAdapter.html#createFromResource(android.content.Context, int, int)

Now I shall take all the glory :)

like image 129
Pedro Oliveira Avatar answered Apr 22 '26 00:04

Pedro Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!