我正在编写一个活动类,如下所示
public class HeaderFooter extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.headerfooter);
}
}
我正在从HeaderFooter类扩展一个类
public class Home extends HeaderFooter
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(Home.this, R.layout.home, vg);
}
}
如何在listitemclick事件
上从基类调用扩展类如果我尝试使用以下代码
Intent i=new Intent(HeaderFooter .this, Home .class);
startActivity(i);
我得到异常告诉我如何从我的主类调用扩展类。
异常详情:
03-21 07:17:44.173: E/AndroidRuntime(1522): FATAL EXCEPTION: main
03-21 07:17:44.173: E/AndroidRuntime(1522): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pcmac.parentconnect/com.pcmac.parentconnect.Grades}: java.lang.NullPointerException
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.os.Looper.loop(Looper.java:137)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-21 07:17:44.173: E/AndroidRuntime(1522): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 07:17:44.173: E/AndroidRuntime(1522): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 07:17:44.173: E/AndroidRuntime(1522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-21 07:17:44.173: E/AndroidRuntime(1522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-21 07:17:44.173: E/AndroidRuntime(1522): at dalvik.system.NativeStart.main(Native Method)
03-21 07:17:44.173: E/AndroidRuntime(1522): Caused by: java.lang.NullPointerException
03-21 07:17:44.173: E/AndroidRuntime(1522): at com.pcmac.parentconnect.LayerStack.onCreate(LayerStack.java:174)
03-21 07:17:44.173: E/AndroidRuntime(1522): at com.pcmac.parentconnect.Grades.onCreate(Grades.java:15)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.Activity.performCreate(Activity.java:5104)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-21 07:17:44.173: E/AndroidRuntime(1522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-21 07:17:44.173: E/AndroidRuntime(1522): ... 11 more
答案 0 :(得分:0)
在这种情况下,您希望使用Intent的其他构造函数:
Intent i = new Intent();
i.setClassName(context, getTargetActivityClassName() /* child class override this method and return a string */);