ArrayAdapter requires the resource ID to be a TextView

      

在测试Spinner的时候,使用ArrayAdapter作为构造器,运行的时候报错,如上图:

代码:

List<String> list = new ArrayList<String>();
        list.add("张三");
        list.add("lisi");
        list.add("wangwu");
        list.add("张三");
        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.item,list);

        spLB.setAdapter(adapter);

构造的Item显示布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=".."
        ></TextView>
</LinearLayout>

百度得知,ITEM布局文件的根节点应该是TextView,修改即可

时间: 2024-08-23 23:19:18

ArrayAdapter requires the resource ID to be a TextView的相关文章

如何解决ArrayAdapter requires the resource ID to be a TextView

今天碰到这样一个难题,搞了很久都没搞定,到网上搜索了一下,发现有很多人都在问这样的问题,现在将自己解决和分析的结果放置如下: 在ArrayAdapter()这个类中有多个构造方法,我仅据此列以作代表: ArrayAdapter(Context context ,int textViewResourceId ,List<T> objects) 参数: context    ----> the current context textViewResourceId ----> the r

appium简明教程(11)——使用resource id定位

上一节乙醇带大家了解了appium的定位策略.实际上appium的控件定位方式是完全遵守webdriver的mobile扩展协议的. 这一节将分享一下如何使用resource id来定位android策略. 什么是resource id,这个不属于本文的范畴,大家可以点这里了解. 我们可以有两种方式来使用resource id进行定位: 使用 findElement(By.id("resourceId")) 的方式.这也是原生的webdriver定义的方法,不过竟然在appium的官方

android.content.res.Resources$NotFoundException:String resource ID #ffffffff

无语,搞了半天,只能去插这个错误代号,结果就找到了这个结果. scoreTextView.setText(score+""); 这个一定要自己手动转换..不科学啊..关键是在eclipse里的提示错误让人以为是id写错了什么的. 以下是别人的一片文章: http://www.blogjava.net/anchor110/articles/355670.html 今天跑程序的时候,出现这样的错误: android.content.res.Resources$NotFoundExcepti

bug android.content.res.Resources$NotFoundException: String resource ID #0x0

android.content.res.Resources$NotFoundException: String resource ID #0x0 找不到资源文件ID #0x0 原因分析如下: 遇到这种情况,很有可能是把一个int型业务数据的 设置setText()或者类似的方法中, 这样Android系统就会主动去资源文件当中寻找, 但是它不是一个资源文件ID, 所以就会报出这个bug. 将int型业务数据,转换成String类型即可.

android编程常见问题- Resource ID #0x7f070001 type #0x12 is not valid

问题说明: AndroidRuntime(1705): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitytest/com.example.activitytest.SecondActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f070001 type #0x12 is n

view.setTag(key,Object) (java.lang.IllegalArgumentException: The key must be an application-specific resource id.)

转自: http://blog.csdn.net/brokge/article/details/8536906 setTag是android的view类中很有用的一个方法,可以用它来给空间附加一些信息,在很多场合下都得到妙用. setTag(Object tag)方法比较简单,这里主要谈一谈带两个参数的setTag方法. 官方的api文档中提到:" The specified key should be an id declared in the resources of the applica

android.content.res.Resources$NotFoundException: String resource ID #0x11

在练习数据绑定时,出现以下错误 FATAL EXCEPTION: main                                                                               Process: com.vogella.android.databinding, PID: 8332                                                                               andr

异常处理android.content.res.Resources$NotFoundException: String resource ID #0x44

错误:android.content.res.Resources$NotFoundException: String resource ID #0x1 原因:一般发生在参数 int resId 错误,你把String赋值给int的resId,所以编译器找不到正确的resource于是报错. 最简单的例子,检查一下你的Toast.makeText()啊textView.setText啊之类的函数,这种函数通常有几个重载,如: textView.setText(CharSequence text);

Web Service Error wsse:InvalidSecurity Policy Requires Integrity (Doc ID 1370736.1)

    Web Service Error wsse:InvalidSecurity Policy Requires Integrity (Doc ID 1370736.1) Modified: 13-May-2013 Type: PROBLEM   In this Document   Symptoms   Cause   Solution   References Applies to: Oracle E-Business Suite Integrated SOA Gateway - Ver