Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 错误:错误:不允许使用字符串类型(位于';条目';带值';数组/列表';)_Android_Android Preferences - Fatal编程技术网

Android 错误:错误:不允许使用字符串类型(位于';条目';带值';数组/列表';)

Android 错误:错误:不允许使用字符串类型(位于';条目';带值';数组/列表';),android,android-preferences,Android,Android Preferences,我是android开发的新手,使用eclipe软件开发pref.xml(资源类型prefrence)。这是我的pref.xml代码 <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <EditTextPreference android:title="EditText" and

我是android开发的新手,使用eclipe软件开发pref.xml(资源类型prefrence)。这是我的pref.xml代码

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<EditTextPreference
 android:title="EditText"
 android:key = "name"
 android:summary="Enter Your name"
 ></EditTextPreference>

 <CheckBoxPreference
 android:title="CheckBox"
 android:defaultValue="true"
 android:key="checkBox"
 android:summary="check this box"
 ></CheckBoxPreference>

 <ListPreference
 android:title="List"
 android:key="list"
 android:summary="This Is A List To Choose From"
 android:entries="array/list"
 ></ListPreference>

请帮帮我。。如何处理此错误

我假设您正在尝试从数组资源文件加载条目,对吗?如果是这样,您需要改为使用“@array/list”。所有资源(字符串、id等)在XML中必须以@作为前缀。

更改

android:entries="array/list" 

android:entries="@array/list"

在包资源管理器的res\value文件夹中查找文件名strings.xml。。。 在此文件中添加以下行

<string-array name="list"></string-array>

您的最终文件看起来像

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Muzafar Khan</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>

<string-array name="list"></string-array>

穆扎法尔·汗
设置
你好,世界!

现在保存您的项目。。。享受:)

这个对我很有用

android:entries=“@+array/list”

希望有帮助:)

给出一个错误,您必须使用

android:entries="@+array/list

您需要在“res”文件夹中创建资源类型“arrays”,在pref_general.xml文件中声明数组类型后,将在该文件夹中定义数组元素。 在arrays.xml文件中,可以定义为


@字符串/**数组元素1**
@字符串/**数组元素2**
因此,在pref-general文件中,实际上将数组定义为
android:entryValues=“@array/数组名称


转到值包创建新的xml文件 对于ex-
array.xml
然后

用于引用该文件

此:android:entries=“array/list”必须是android:entries=“@array/list”已尝试但不起作用…您还需要另一个数组属性,称为
entryValues
:android:entryValues=“@array/listValues”。因为
条目
是ListPreference显示的内容。然后在
entryValues
中有相应的值。请您解释一下为什么需要
+
android:entries="@array/list"
android:entries="@+array/list
So in your string file you define the array elements as strings in normal way

Cheers 
<resources>
<string-array name="list"></string-array>
android:entries="array/list"
android:entries="@array/list"