[英]error: Error: String types not allowed (at 'entries' with value 'array/list')
I am new in android development and developing pref.xml (resource type prefrence) using eclipe software. 我是android开发和使用eclipe软件开发pref.xml(资源类型prefrence)的新手。 Here is my pref.xml code 这是我的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>
and i got this error : 我收到了这个错误:
error: Error: String types not allowed (at 'entries' with value 'array/list')
Please help me.. how do i handle this error ? 请帮帮我..我该如何处理这个错误?
Change 更改
android:entries="array/list"
to 至
android:entries="@array/list"
Find file name strings.xml in res\\value folder in your package explorer... add following line in this file 在包浏览器的res \\ value文件夹中查找文件名strings.xml ...在此文件中添加以下行
<string-array name="list"></string-array>
Your Final file look like 你的最终文件看起来像
<?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>
Now save your project... and enjoy :) 现在保存您的项目...并享受:)
I am assuming you are trying to load the entries from the array resource file, correct? 我假设您正在尝试从阵列资源文件中加载条目,对吗? If so, you need to do "@array/list" instead. 如果是这样,你需要改为“@ array / list”。 All of the resources (string, id, etc) must be prefixed with @ in the XML. 所有资源(字符串,id等)都必须在XML中以@为前缀。
This one worked for me 这个对我有用
android:entries="@+array/list"
hope it helps :) 希望能帮助到你 :)
android:entries="@array/list"
给出错误,你必须使用
android:entries="@+array/list
You need to create resource type 'arrays' in the 'res' folder where the array elements will be defined after declaring the array type in the pref_general.xml file. 您需要在'res'文件夹中创建资源类型'arrays',在pref_general.xml文件中声明数组类型后将定义数组元素。 In the arrays.xml file you can define as 在arrays.xml文件中,您可以定义为
<string-array name="**array name**">
<item>@string/**array element 1**</item>
<item>@string/**array element 2**</item>
</string-array>
So in your pref general file you will actually define array as
android:entryValues="@array/ array name " android:entryValues =“@ array / array name ”
So in your string file you define the array elements as strings in normal way
Cheers
go to values package create a new xml file for ex- array.xml
then 转到values包然后为ex- array.xml
创建一个新的xml文件
<resources>
<string-array name="list"></string-array>
set the string-array and change 设置字符串数组并进行更改
android:entries="array/list"
to 至
android:entries="@array/list"
for refering the file : 用于引用文件:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.