[英]App force close in phone but running well in the emulator
My android application running well in the emulator but when i install that app in phone and use it. 我的Android应用程序在模拟器中运行良好,但是当我在手机中安装该应用程序并使用它时。 It is crashed at the second activity on click of the toggle button.
单击切换按钮时,它在第二个活动中崩溃。 The code is below.
代码如下。 The dob is a toggle button and start is the button from where i move on to the next activity.
DOB是一个切换按钮,开始是我继续进行下一个活动的按钮。
dob.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Toggle clicked", Toast.LENGTH_SHORT);
if (dob.isChecked()) {
dob_player=1;
name2.setVisibility(0);
name3.setVisibility(1);
} else {
name2.setVisibility(1);
name3.setVisibility(0);
dob_player=0;
}
}
});
start_game.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(dob_player==1){
username1=name1.getText().toString();
username2=name3.getText().toString();
if(username1.equals("") || username2.equals("")){
Toast.makeText(start.this, "Enter the name of the Players", Toast.LENGTH_SHORT);
AlertDialog.Builder alertbox = new AlertDialog.Builder(start.this);
alertbox.setMessage("Enter the name of the Players");
alertbox.setNeutralButton("Ok",
new DialogInterface.OnClickListener() {
// Click listener on the neutral button of alert box
public void onClick(DialogInterface arg0, int arg1) {
// mp1.stop();
//mp1.release();
}
});
alertbox.show();
}
else{
Bundle bundle=new Bundle();
bundle.putInt("qualifying",right);
Intent start=new Intent(start.this,game_double.class);
start.putExtras(bundle);
startActivityForResult(start, 0);
}
}
else{
username1=name1.getText().toString();
Bundle bundle=new Bundle();
bundle.putInt("qualifying",right);
Intent start=new Intent(start.this,game.class);
start.putExtras(bundle);
startActivityForResult(start, 0);
}
}
});
My logcat is as below. 我的logcat如下。
1.It comes when press the toggle button 1.按下切换按钮时
05-10 10:52:49.453: E/ERROR(17394): ERROR
05-10 10:52:49.453: E/ERROR(17394): java.lang.NullPointerException
05-10 10:52:49.453: E/ERROR(17394): at com.ktrivia.in.start$5.onClick(start.java:129)
05-10 10:52:49.453: E/ERROR(17394): at android.view.View.performClick(View.java:2485)
05-10 10:52:49.453: E/ERROR(17394): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
05-10 10:52:49.453: E/ERROR(17394): at android.view.View$PerformClick.run(View.java:9080)
05-10 10:52:49.453: E/ERROR(17394): at android.os.Handler.handleCallback(Handler.java:587)
05-10 10:52:49.453: E/ERROR(17394): at android.os.Handler.dispatchMessage(Handler.java:92)
05-10 10:52:49.453: E/ERROR(17394): at android.os.Looper.loop(Looper.java:130)
05-10 10:52:49.453: E/ERROR(17394): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-10 10:52:49.453: E/ERROR(17394): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 10:52:49.453: E/ERROR(17394): at java.lang.reflect.Method.invoke(Method.java:507)
05-10 10:52:49.453: E/ERROR(17394): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-10 10:52:49.453: E/ERROR(17394): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-10 10:52:49.453: E/ERROR(17394): at dalvik.system.NativeStart.main(Native Method)
2.It comes when click on the start button 2.点击开始按钮
05-10 10:54:24.710: D/AndroidRuntime(17394): Shutting down VM
05-10 10:54:24.710: W/dalvikvm(17394): threadid=1: thread exiting with uncaught exception (group=0x40018578)
05-10 10:54:24.710: E/AndroidRuntime(17394): FATAL EXCEPTION: main
05-10 10:54:24.710: E/AndroidRuntime(17394): java.lang.NullPointerException
05-10 10:54:24.710: E/AndroidRuntime(17394): at com.ktrivia.in.start$6.onClick(start.java:150)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.view.View.performClick(View.java:2485)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.view.View$PerformClick.run(View.java:9080)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.os.Handler.handleCallback(Handler.java:587)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.os.Handler.dispatchMessage(Handler.java:92)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.os.Looper.loop(Looper.java:130)
05-10 10:54:24.710: E/AndroidRuntime(17394): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-10 10:54:24.710: E/AndroidRuntime(17394): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 10:54:24.710: E/AndroidRuntime(17394): at java.lang.reflect.Method.invoke(Method.java:507)
05-10 10:54:24.710: E/AndroidRuntime(17394): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-10 10:54:24.710: E/AndroidRuntime(17394): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-10 10:54:24.710: E/AndroidRuntime(17394): at dalvik.system.NativeStart.main(Native Method)
The application is crashed on click of these two buttons. 单击这两个按钮会导致应用程序崩溃。 This is new prob for me.
这对我来说是新问题。 If anyone have any idea about this then please help me.
如果有人对此有任何想法,请帮助我。
try using this 尝试使用这个
Intent intent=new Intent(CurrentActivity.this,NextActivity.class);
replace start.this with CurrentActivity.this 用CurrentActivity.this替换start.this
maybe you are using Activity and intent name same so maybe causing problem.so try this: 也许您使用的Activity和Intent名称相同,所以可能导致问题。请尝试以下操作:
AlertDialog alert =alertbox .create();
alert.show();
else{
Intent intent=new Intent(start.this,game_double.class);
Bundle bundle=new Bundle();
bundle.putInt("qualifying",right);
intent.putExtras(bundle);
startActivityForResult(intent, 0);
}
}
else{
username1=name1.getText().toString();
Intent intent=new Intent(start.this,game.class);
Bundle bundle=new Bundle();
bundle.putInt("qualifying",right);
intent.putExtras(bundle);
startActivityForResult(intent, 0);
}
try 尝试
Intent start = new Intent(getApplicationContext(),game_double.class)
instead of 代替
Intent start = new Intent(start.this,game.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.