Java code android process stopped

**Solution** I used only `setContentView(R.layout.menu);` I also needed `setContentView(R.layout.l2class);` **Original Question** I have loadscreen > menu > menu_2. When I choose menu_2 I have error. `My process stopped` package com.lineage.goddess; public class l2class extends Activity { private static final int SHOW_1 = 1; private static final int SHOW_2 = 2; private static final int SHOW_3 = 3; private static final int SHOW_4 = 4; private static final int SHOW_5 = 5; private static final int SHOW_6 = 6; private static final int SHOW_7 = 7; private static final int SHOW_8 = 8; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.menu); Button act8 = (Button)findViewById(R.id.button8); act8.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, wynnsummoner.class); startActivityForResult(i, SHOW_8); } }); Button act7 = (Button)findViewById(R.id.button7); act7.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, eolhhealer.class); startActivityForResult(i, SHOW_7); } }); Button act6 = (Button)findViewById(R.id.button6); act6.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, sigelknight.class); startActivityForResult(i, SHOW_6); } }); Button act5 = (Button)findViewById(R.id.button5); act5.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, isenchanter.class); startActivityForResult(i, SHOW_5); } }); Button act4 = (Button)findViewById(R.id.button4); act4.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, othelrogue.class); startActivityForResult(i, SHOW_4); } }); Button act3 = (Button)findViewById(R.id.button3); act3.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, tirwarrior.class); startActivityForResult(i, SHOW_3); } }); Button act2 = (Button)findViewById(R.id.button2); act2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, yrarcher.class); startActivityForResult(i, SHOW_2); } }); Button act1 = (Button)findViewById(R.id.button1); act1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(l2class.this, feohwizard.class); startActivityForResult(i, SHOW_1); } }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case SHOW_1://case show_1 break; case SHOW_2://case show_2 break; case SHOW_3://case show_3 break; case SHOW_4://case show_4 break; case SHOW_5://case show_5 break; case SHOW_6://case show_6 break; case SHOW_7://case show_7 break; case SHOW_8://case show_8 break; }//switch }//if result_ok }//onactivityresult //TODO: Fill In Methods Etc. }//class Menu 1: package com.lineage.goddess; public class menu extends Activity { private static final int SHOW_1 = 1; private static final int SHOW_2 = 2; private static final int SHOW_3 = 3; private static final int SHOW_4 = 4; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.menu); Button act4 = (Button)findViewById(R.id.button2); act4.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(menu.this, l2class.class); startActivityForResult(i, SHOW_4); } }); Button act3 = (Button)findViewById(R.id.button3); act3.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(menu.this, location.class); startActivityForResult(i, SHOW_3); } }); Button act2 = (Button)findViewById(R.id.button4); act2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(menu.this, help.class); startActivityForResult(i, SHOW_2); } }); Button act1 = (Button)findViewById(R.id.button1); act1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(menu.this, room.class); startActivityForResult(i, SHOW_1); } }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case SHOW_1://case show_1 break; case SHOW_2://case show_2 break; case SHOW_3://case show_3 break; case SHOW_4://case show_4 break; }//switch }//if result_ok }//onactivityresult }//class Logcat : 12-22 22:19:12.493: E/AndroidRuntime(300): FATAL EXCEPTION: main 12-22 22:19:12.493: E/AndroidRuntime(300): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lineage.goddess/com.lineage.goddess.l2class}: java.lang.NullPointerException 12-22 22:19:12.493: E/AndroidRuntime(300): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lineage.goddess/com.lineage.goddess.l2class}: java.lang.NullPointerException 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.os.Handler.dispatchMessage(Handler.java:99) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.os.Looper.loop(Looper.java:123) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread.main(ActivityThread.java:4627) 12-22 22:19:12.493: E/AndroidRuntime(300): at java.lang.reflect.Method.invokeNative(Native Method) 12-22 22:19:12.493: E/AndroidRuntime(300): at java.lang.reflect.Method.invoke(Method.java:521) 12-22 22:19:12.493: E/AndroidRuntime(300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 12-22 22:19:12.493: E/AndroidRuntime(300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 12-22 22:19:12.493: E/AndroidRuntime(300): at dalvik.system.NativeStart.main(Native Method) 12-22 22:19:12.493: E/AndroidRuntime(300): Caused by: java.lang.NullPointerException 12-22 22:19:12.493: E/AndroidRuntime(300): at com.lineage.goddess.l2class.onCreate(l2class.java:32) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 12-22 22:19:12.493: E/AndroidRuntime(300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 12-22 22:19:12.493: E/AndroidRuntime(300): ... 11 more
What does logcat say?

以上就是Java code android process stopped的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏