私は単純な Android リスト ビューを作成しましたが、実行時に java.lang.NullPointerException をスローしています。デバッグ モードで確認したところ、findViewbyId が null を返しているようです。そのため、setAdapter に到達すると、例外がスローされます。ただし、リストは R.java ファイルと main.xml に存在します。どうすればこれを修正できますか?
setContentView(my.namespace.R.layout.main);
String[] a={"asd","asdsad"};
ListView lt;
lt = (ListView) findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,my.namespace.R.layout.rowitem, a);
lt.setAdapter(adapter);
Main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>