当试图打开一个活动时,它显示错误,表示活动无法实例化。我有一个gridview,它必须打开不同的活动,当gridview处于mainactivity时,没有问题但是当网格视图在另一个活动中时,问题是araises
package com.guru.finalpro1;
公共类Level1扩展Activity实现AdapterView.OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
GridView gva= (GridView)findViewById(R.id.gridView1);
gva.setAdapter(new ImageAdaptera(getApplicationContext()));
gva.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
switch(position){
case 0:
{
Intent intenta = new Intent (Level1.this, AA.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intenta,0);
}
break;
case 1:
{
Intent intentb = new Intent (Level1.this, AB.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intentb,0);
}
break;
case 2:
{
Intent intentc = new Intent (getBaseContext(), AC.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intentc,0);
}
break;
案例3: { Intent intentd = new Intent(getBaseContext(),AD.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intentd,0); } 打破;
案例4: { Intent intente = new Intent(getBaseContext(),AE.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intente,0); } 打破;
}}
错误:
10-12 04:55:13.543:E / AndroidRuntime(1145):致命异常:主要 10-12 04:55:13.543:E / AndroidRuntime(1145):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.guru.finalpro1 / com.guru.finalpro1.AA}:java.lang.NullPointerException 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread.access $ 600(ActivityThread.java:141) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.os.Handler.dispatchMessage(Handler.java:99) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.os.Looper.loop(Looper.java:137) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread.main(ActivityThread.java:5103) 10-12 04:55:13.543:E / AndroidRuntime(1145):at java.lang.reflect.Method.invokeNative(Native Method) 10-12 04:55:13.543:E / AndroidRuntime(1145):at java.lang.reflect.Method.invoke(Method.java:525) 10-12 04:55:13.543:E / AndroidRuntime(1145):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 10-12 04:55:13.543:E / AndroidRuntime(1145):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-12 04:55:13.543:E / AndroidRuntime(1145):at dalvik.system.NativeStart.main(Native Method) 10-12 04:55:13.543:E / AndroidRuntime(1145):引起:java.lang.NullPointerException 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.Activity.findViewById(Activity.java:1853) 10-12 04:55:13.543:E / AndroidRuntime(1145):at com.guru.finalpro1.AA。(AA.java:26) 10-12 04:55:13.543:E / AndroidRuntime(1145):at java.lang.Class.newInstanceImpl(Native Method) 10-12 04:55:13.543:E / AndroidRuntime(1145):at java.lang.Class.newInstance(Class.java:1130) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.Instrumentation.newActivity(Instrumentation.java:1061) 10-12 04:55:13.543:E / AndroidRuntime(1145):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128) 10-12 04:55:13.543:E / AndroidRuntime(1145):... 11更多