简体   繁体   English

错误:错误:不允许字符串类型(在'条目'处,值为'array / list')

[英]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.

相关问题 Android-错误:不允许使用字符串类型(在“ imageViewScramble”中值为“”) - Android - Error:String types not allowed (at 'imageViewScramble' with value '') 错误:不允许使用字符串类型(在'screenOrientation'中,值为'sensorPortait') - Error: String types not allowed (at 'screenOrientation' with value 'sensorPortait') 错误:不允许使用字符串类型 - Error:String types not allowed 错误:错误:不允许的字符串类型(在“ layout_gravity”,值为“ start”) - error: Error: String types not allowed (at 'layout_gravity' with value 'start') Android + Admob:错误:不允许的字符串类型(在&#39;configChanges&#39;与值(等)) - Android+Admob: Error: String types not allowed (at 'configChanges' with value(etc…) 错误:(23,26)不允许使用字符串类型(在&#39;src&#39;中值为&#39;pen&#39;)。 - Error:(23, 26) String types not allowed (at 'src' with value 'pen').? 错误:Android Studio中不允许使用字符串类型(在“主题”中值为“”) - Error : String types not allowed (at 'theme' with value ") in android studio 错误:不允许使用字符串类型(值“失败”时)@ values / values.xml - Error: String types not allowed (at 'fail' with value) @values/values.xml 错误:错误:不允许整数类型(在“ Dimens”处,值为“ 1”) - error: Error: Integer types not allowed (at 'Dimens' with value '1') Eclipse / Android错误:不允许使用字符串类型 - Eclipse/Android error: String types not allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM