ArrayAdapter requires the resource ID to be a TextView问题整理
2016-09-27 16:27
661 查看
今天在编写一个ActionBar的应用的时候,出现了一个错误,错误如下:
09-27 16:20:28.331: D/AndroidRuntime(18088): Shutting down VM
09-27 16:20:28.333: E/AndroidRuntime(18088): FATAL EXCEPTION: main
09-27 16:20:28.333: E/AndroidRuntime(18088): Process: com.example.gunqustudy, PID: 18088
09-27 16:20:28.333: E/AndroidRuntime(18088): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
……
09-27 16:20:28.333: E/AndroidRuntime(18088): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
……
这个异常的意思是ArrayAdapter需要的资源ID必须是TextView的。
最初错误代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/textview"
/>
</LinearLayout>
正确代码:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/textview"
/>
因为根节点必须是TextView
09-27 16:20:28.331: D/AndroidRuntime(18088): Shutting down VM
09-27 16:20:28.333: E/AndroidRuntime(18088): FATAL EXCEPTION: main
09-27 16:20:28.333: E/AndroidRuntime(18088): Process: com.example.gunqustudy, PID: 18088
09-27 16:20:28.333: E/AndroidRuntime(18088): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
……
09-27 16:20:28.333: E/AndroidRuntime(18088): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
……
这个异常的意思是ArrayAdapter需要的资源ID必须是TextView的。
最初错误代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/textview"
/>
</LinearLayout>
正确代码:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/textview"
/>
因为根节点必须是TextView
相关文章推荐
- ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView问题
- 关于出现 ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView问题
- ArrayAdapter requires the resource ID to be a TextView错误
- 如何解决ArrayAdapter requires the resource ID to be a TextView
- 报错:ArrayAdapter requires the resource ID to be a TextView
- ArrayAdapter requires the resource ID to be a TextView 的解决办法
- Q: ArrayAdapter requires the resource ID to be a TextView
- 如何解决ArrayAdapter requires the resource ID to be a TextView
- ArrayAdapter requires the resource id to be a TextView
- ArrayAdapter requires the resource ID to be a TextView
- ArrayAdapter requires the resource ID to be a TextView错误
- 如何解决ArrayAdapter requires the resource ID to be a TextView
- ArrayAdapter requires the resource ID to be a TextView错误
- ArrayAdapter的用法:ArrayAdapter(Context context, int textViewResourceId, T[] objects)