gpt4 book ai didi

java.lang.IllegalStateException : ArrayAdapter requires the resource ID to be a TextView 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:20 25 4
gpt4 key购买 nike

<分区>

我试过这个教程 http://windrealm.org/tutorials/android/android-listview.php “一个简单的 Android ListView 示例”

但是在我在 Eclipse 中的测试中,我在 android 应用程序中崩溃了。

在 LogCat 中我有这个:

04-11 20:17:24.170: E/AndroidRuntime(7062): 
java.lang.IllegalStateException: ArrayAdapter requires the resource ID
to be a TextView

为什么会崩溃?

java类

private ListView mainListView;
private ArrayAdapter<String> listAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mains);

mainListView = (ListView) findViewById(R.id.mainListView);

String[] xRemote = Remote.split(";");

ArrayList<String> planetList = new ArrayList<String>();

planetList.addAll(Arrays.asList(xRemote));

listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,
planetList);

listAdapter.addAll(xRemote);

mainListView.setAdapter(listAdapter);

ma​​ins.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainListView">
</ListView
</LinearLayout>

simplerow.xml

<?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/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

</LinearLayout>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com