初めての Android アプリケーションをプログラミングしていますが、問題が発生しました。新しいアクティビティを開こうとすると、アプリがシャットダウンします。
アクティビティ コードは次のとおりです。
package com.WNF;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.ListActivity;
import android.content.Intent;
public class Actiemenu extends ListActivity{
String[] array = { "","henk","henk2" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.actiemenu);
setListAdapter(new ArrayAdapter<String> (this, R.layout.actiemenu, array));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
if (position == 0) {
Intent een = new Intent(Actiemenu.this, Acties.class);
startActivity(een);
}
else if (position == 1) {
Intent twee = new Intent(Actiemenu.this, Acties2.class);
startActivity(twee);
}
}
});
getIntent();
}
}
そして、これは logcat のログです:
06-13 06:50:13.920: E/AndroidRuntime(335): FATAL EXCEPTION: main
06-13 06:50:13.920: E/AndroidRuntime(335): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ListView.makeAndAddView(ListView.java:1745)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ListView.fillDown(ListView.java:670)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ListView.fillFromTop(ListView.java:727)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ListView.layoutChildren(ListView.java:1598)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.View.layout(View.java:7175)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.View.layout(View.java:7175)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.View.layout(View.java:7175)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.View.layout(View.java:7175)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.View.layout(View.java:7175)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
06-13 06:50:13.920: E/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-13 06:50:13.920: E/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 06:50:13.920: E/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:507)
06-13 06:50:13.920: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-13 06:50:13.920: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-13 06:50:13.920: E/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
06-13 06:50:13.920: E/AndroidRuntime(335): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
06-13 06:50:13.920: E/AndroidRuntime(335): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
06-13 06:50:13.920: E/AndroidRuntime(335): ... 30 more