无法解析符号'createFromResource“ [英] Cannot resolve symbol 'createFromResource'

查看:210
本文介绍了无法解析符号'createFromResource“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来这是什么意思完全糊涂了。香港专业教育学院做了一些搜索,但到目前为止还没有发现任何帮助。

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

我采用了android工作室,并在

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以红色反白标明的,当我将鼠标悬停它它说:无法解析符号'createFromResource'。

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

我的数组

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

我的布局

<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"/>

任何帮助将大大AP preciated,谢谢!

Any help would be greatly appreciated, thanks!

推荐答案

正是这样Spidy不要把所有的荣​​耀)

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

您所呼叫,将返回你一个arrayadapter,所以你不应该使用,因为你没有任何实例。

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.

您应该做这种方式:

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

有关引用:<一href=\"http://developer.android.com/reference/android/widget/ArrayAdapter.html#createFromResource(android.content.Context\">http://developer.android.com/reference/android/widget/ArrayAdapter.html#createFromResource(android.content.Context, INT,INT)

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

现在我将所有的荣耀:)

Now I shall take all the glory :)

这篇关于无法解析符号'createFromResource“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆