I am trying to learn screen navigation in android
我试图实现如下
- 当我单击活动中的按钮时,它会启动一个新活动
- 但是该最终活动必须在单击时包含一个后退按钮,它应该返回第一个活动
生病在下面发布一些描述性代码
CopperchimneyDesc.java
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.copperchimney_desc_screen);
Button PHOTOBUTTON=(Button) findViewById(R.id.CopperChimneyPhotosButton);
PHOTOBUTTON.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pht=new Intent(CopperChimneyDesc.this,CopperChimneyPhotos.class);
startActivity(pht);
}
});
CopperChimneyPhotos.java
public class CopperChimneyPhotos extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.copper_chimney_photos);
Button btn=(Button) findViewById(R.id.PhotoButton);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pt=new Intent(CopperChimneyPhotos.this,CopperChimneyDesc.class);
startActivity(pt);
}
});
}
PS:: 我已经在清单中声明了新活动
我的错误日志如下::
08-16 17:42:33.730: E/AndroidRuntime(444): FATAL EXCEPTION: main
08-16 17:42:33.730: E/AndroidRuntime(444): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.findmybuffet/com.project.findmybuffet.CopperChimneyDesc}: java.lang.NullPointerException
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.os.Looper.loop(Looper.java:123)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-16 17:42:33.730: E/AndroidRuntime(444): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 17:42:33.730: E/AndroidRuntime(444): at java.lang.reflect.Method.invoke(Method.java:507)
08-16 17:42:33.730: E/AndroidRuntime(444): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-16 17:42:33.730: E/AndroidRuntime(444): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-16 17:42:33.730: E/AndroidRuntime(444): at dalvik.system.NativeStart.main(Native Method)
08-16 17:42:33.730: E/AndroidRuntime(444): Caused by: java.lang.NullPointerException
08-16 17:42:33.730: E/AndroidRuntime(444): at com.project.findmybuffet.CopperChimneyDesc.onCreate(CopperChimneyDesc.java:39)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-16 17:42:33.730: E/AndroidRuntime(444): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-16 17:42:33.730: E/AndroidRuntime(444): ... 11 more
关于如何克服这个问题的任何想法,我都粘贴了相关代码。