如何通过字符串数组 android 将自定义 listView 项目扩展到超过 10 个项目?
How to extend custom listView item more than 10 items through String array android?
I want to create custom list more than 10 elements. When I fill an
String array more than 10 elements and click the 11th item then app
isn't run.
public class MainActivity extends Activity {
ListView listView;
int position=0;
String[]items={"ab","cd","ef","gh","jk","lm","no","pr","st","uv","wx"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.lv_country);
ArrayAdapter<String>arrayAdapter=new ArrayAdapter<String>(this,R.layout.custom_list,items);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
{
Intent intent;
position=p3;
switch(p3){
case 0:
intent=new Intent(MainActivity.this,Hi.class);
startActivity(intent);
case 1:
intent=new Intent(MainActivity.this,Ba.class);
startActivity(intent);
break;
case 2:
intent=new Intent(MainActivity.this,Dc.class);
startActivity(intent);
break;
case 3:
intent=new Intent(MainActivity.this,Fe.class);
startActivity(intent);
break;
case 4:
intent=new Intent(MainActivity.this,Hg.class);
startActivity(intent);
break;
case 5:
intent=new Intent(MainActivity.this,Kj.class);
startActivity(intent);
break;
case 6:
intent=new Intent(MainActivity.this,Ml.class);
startActivity(intent);
break;
case 7:
intent=new Intent(MainActivity.this,On.class);
startActivity(intent);
break;
case 8:
intent=new Intent(MainActivity.this,Rp.class);
startActivity(intent);
break;
case 9:
intent=new Intent(MainActivity.this,Ts.class);
startActivity(intent);
break;
case 10:
intent=new Intent(MainActivity.this, Spinner_Activity.class);
startActivity(intent);
}
}
});
}
}
at
android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6743)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6717)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6663)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6846)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native
Method) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:177)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6817)
05-18 09:49:57.933 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6869)
05-18 09:49:57.934 14335 14335 E AndroidRuntime
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer.doCallbacks(Choreographer.java:778)
05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer.doFrame(Choreographer.java:707) 05-18
09:49:57.934 14335 14335 E AndroidRuntime
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18
09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18
09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 09:49:57.934 14335
14335 E AndroidRuntime at
android.app.ActivityThread.main(ActivityThread.java:6809) 05-18
09:49:57.934 14335 14335 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 09:49:57.934
14335 14335 E AndroidRuntime at
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
05-18 09:49:57.934 14335 14335 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
FATAL EXCEPTION: main 05-18 09:49:57.940 14335 14335 E
AndroidRuntime Process:
com.mycompany.myapp, PID: 14335 05-18 09:49:57.940 14335 14335 E
AndroidRuntime
android.content.ActivityNotFoundException: Unable to find explicit
activity class
{com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you
declared this activity in your AndroidManifest.xml? 05-18 09:49:57.940
14335 14335 E AndroidRuntime at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2123)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1801)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4495)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4453)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4814) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4782) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at
com.mycompany.myapp.List_Widgets0000000.onItemClick(List_Widgets.java:75)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.performItemClick(AbsListView.java:1197)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3166)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.onTouchUp(AbsListView.java:4131) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3878)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.View.dispatchTouchEvent(View.java:11776) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2959)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2636)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:446)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1848)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.dispatchTouchEvent(Activity.java:3315) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at
com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:408)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.View.dispatchPointerEvent(View.java:12015) 05-18
09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4855)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4638)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4222)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4188)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4315)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4372)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4222)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4188)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6743)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6717)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6663)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6846)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native
Method) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:177)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6817)
05-18 09:49:57.940 14335 14335 E AndroidRuntime
at
android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6869)
05-18 09:49:57.941 14335 14335 E AndroidRuntime
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer.doCallbacks(Choreographer.java:778)
05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer.doFrame(Choreographer.java:707) 05-18
09:49:57.941 14335 14335 E AndroidRuntime
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18
09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18
09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 09:49:57.941 14335
14335 E AndroidRuntime at
android.app.ActivityThread.main(ActivityThread.java:6809) 05-18
09:49:57.941 14335 14335 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 09:49:57.941
14335 14335 E AndroidRuntime at
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
05-18 09:49:57.941 14335 14335 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
FATAL EXCEPTION: main 05-18 12:10:59.002 29469 29469 E
AndroidRuntime Process:
com.mycompany.myapp, PID: 29469 05-18 12:10:59.002 29469 29469 E
AndroidRuntime
android.content.ActivityNotFoundException: Unable to find explicit
activity class
{com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you
declared this activity in your AndroidManifest.xml? 05-18 12:10:59.002
29469 29469 E AndroidRuntime at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2123)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1801)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4495)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4453)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4814) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4782) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at
com.mycompany.myapp.List_Widgets0000000.onItemClick(List_Widgets.java:88)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView.performItemClick(AbsListView.java:1197)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3166)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView.run(AbsListView.java:4119) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 12:10:59.002 29469
29469 E AndroidRuntime at
android.app.ActivityThread.main(ActivityThread.java:6809) 05-18
12:10:59.002 29469 29469 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 12:10:59.002
29469 29469 E AndroidRuntime at
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
05-18 12:10:59.002 29469 29469 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18
12:10:59.008 29469 29469 E AndroidRuntime
FATAL EXCEPTION: main
Unable to find explicit activity class {com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you declared this activity in your AndroidManifest.xml?
根据您的 logcat,我认为您忘记将 Spinner_Activity 添加到 Manifest 文件。检查那里是否存在 Spinner_Activity。如果没有,只需将其添加到那里。
<activity android:name=".Spinner_Activity"></activity>
我建议您通过菜单 File -> New -> Activity -> Empty Activity 创建新活动,studio 会同时创建 activity, layout and note in manifest 本身。
至于我,你的代码运行良好
I want to create custom list more than 10 elements. When I fill an String array more than 10 elements and click the 11th item then app isn't run.
public class MainActivity extends Activity {
ListView listView;
int position=0;
String[]items={"ab","cd","ef","gh","jk","lm","no","pr","st","uv","wx"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.lv_country);
ArrayAdapter<String>arrayAdapter=new ArrayAdapter<String>(this,R.layout.custom_list,items);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
{
Intent intent;
position=p3;
switch(p3){
case 0:
intent=new Intent(MainActivity.this,Hi.class);
startActivity(intent);
case 1:
intent=new Intent(MainActivity.this,Ba.class);
startActivity(intent);
break;
case 2:
intent=new Intent(MainActivity.this,Dc.class);
startActivity(intent);
break;
case 3:
intent=new Intent(MainActivity.this,Fe.class);
startActivity(intent);
break;
case 4:
intent=new Intent(MainActivity.this,Hg.class);
startActivity(intent);
break;
case 5:
intent=new Intent(MainActivity.this,Kj.class);
startActivity(intent);
break;
case 6:
intent=new Intent(MainActivity.this,Ml.class);
startActivity(intent);
break;
case 7:
intent=new Intent(MainActivity.this,On.class);
startActivity(intent);
break;
case 8:
intent=new Intent(MainActivity.this,Rp.class);
startActivity(intent);
break;
case 9:
intent=new Intent(MainActivity.this,Ts.class);
startActivity(intent);
break;
case 10:
intent=new Intent(MainActivity.this, Spinner_Activity.class);
startActivity(intent);
}
}
});
}
}
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6743) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6717) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6663) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6846) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:177) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6817) 05-18 09:49:57.933 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6869) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer.doCallbacks(Choreographer.java:778) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer.doFrame(Choreographer.java:707) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 09:49:57.934 14335 14335 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:6809) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 09:49:57.934 14335 14335 E AndroidRuntime at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 05-18 09:49:57.934 14335 14335 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
FATAL EXCEPTION: main 05-18 09:49:57.940 14335 14335 E
AndroidRuntime Process: com.mycompany.myapp, PID: 14335 05-18 09:49:57.940 14335 14335 E
AndroidRuntime
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you declared this activity in your AndroidManifest.xml? 05-18 09:49:57.940 14335 14335 E AndroidRuntime at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2123) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1801) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4495) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4453) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4814) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4782) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at com.mycompany.myapp.List_Widgets0000000.onItemClick(List_Widgets.java:75) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AdapterView.performItemClick(AdapterView.java:318) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.performItemClick(AbsListView.java:1197) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3166) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.onTouchUp(AbsListView.java:4131) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3878) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.View.dispatchTouchEvent(View.java:11776) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2959) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2636) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2965) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2650) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:446) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1848) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.app.Activity.dispatchTouchEvent(Activity.java:3315) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:408) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.View.dispatchPointerEvent(View.java:12015) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4855) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4638) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4222) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4188) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4315) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4372) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4222) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4188) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4196) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4169) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6743) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6717) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6663) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6846) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:177) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6817) 05-18 09:49:57.940 14335 14335 E AndroidRuntime
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6869) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer.doCallbacks(Choreographer.java:778) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer.doFrame(Choreographer.java:707) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 09:49:57.941 14335 14335 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:6809) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 09:49:57.941 14335 14335 E AndroidRuntime at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 05-18 09:49:57.941 14335 14335 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
FATAL EXCEPTION: main 05-18 12:10:59.002 29469 29469 E
AndroidRuntime Process: com.mycompany.myapp, PID: 29469 05-18 12:10:59.002 29469 29469 E
AndroidRuntime
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you declared this activity in your AndroidManifest.xml? 05-18 12:10:59.002 29469 29469 E AndroidRuntime at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2123) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1801) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4495) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivityForResult(Activity.java:4453) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4814) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.app.Activity.startActivity(Activity.java:4782) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at com.mycompany.myapp.List_Widgets0000000.onItemClick(List_Widgets.java:88) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AdapterView.performItemClick(AdapterView.java:318) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView.performItemClick(AbsListView.java:1197) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3166) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.widget.AbsListView.run(AbsListView.java:4119) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Handler.handleCallback(Handler.java:789) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Handler.dispatchMessage(Handler.java:98) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at android.os.Looper.loop(Looper.java:164) 05-18 12:10:59.002 29469 29469 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:6809) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at java.lang.reflect.Method.invoke(Native Method) 05-18 12:10:59.002 29469 29469 E AndroidRuntime at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 05-18 12:10:59.002 29469 29469 E AndroidRuntime
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 05-18 12:10:59.008 29469 29469 E AndroidRuntime
FATAL EXCEPTION: main
Unable to find explicit activity class {com.mycompany.myapp/com.mycompany.myapp.Spinner_Activity}; have you declared this activity in your AndroidManifest.xml?
根据您的 logcat,我认为您忘记将 Spinner_Activity 添加到 Manifest 文件。检查那里是否存在 Spinner_Activity。如果没有,只需将其添加到那里。
<activity android:name=".Spinner_Activity"></activity>
我建议您通过菜单 File -> New -> Activity -> Empty Activity 创建新活动,studio 会同时创建 activity, layout and note in manifest 本身。
至于我,你的代码运行良好