您好这是我在Android上制作的第一个应用程序,我完成了我的应用程序没有任何问题,但突然我有这个错误,我不知道为什么它不工作,因为它之前工作正常。我不明白如何阅读原木猫所以请帮帮我!
07-24 12:00:15.170: D/AndroidRuntime(1866): Shutting down VM
07-24 12:00:15.170: W/dalvikvm(1866): threadid=1: thread exiting with uncaught exception (group=0xb1cefb20)
07-24 12:00:15.190: E/AndroidRuntime(1866): FATAL EXCEPTION: main
07-24 12:00:15.190: E/AndroidRuntime(1866): Process: com.sachinda.myfirstapp, PID: 1866
07-24 12:00:15.190: E/AndroidRuntime(1866): java.lang.NullPointerException
07-24 12:00:15.190: E/AndroidRuntime(1866): at com.sachinda.myfirstapp.TwoPlayerActivity.onClick(TwoPlayerActivity.java:157)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.view.View.performClick(View.java:4438)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.view.View$PerformClick.run(View.java:18422)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.os.Handler.handleCallback(Handler.java:733)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.os.Handler.dispatchMessage(Handler.java:95)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.os.Looper.loop(Looper.java:136)
07-24 12:00:15.190: E/AndroidRuntime(1866): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-24 12:00:15.190: E/AndroidRuntime(1866): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:00:15.190: E/AndroidRuntime(1866): at java.lang.reflect.Method.invoke(Method.java:515)
07-24 12:00:15.190: E/AndroidRuntime(1866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-24 12:00:15.190: E/AndroidRuntime(1866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-24 12:00:15.190: E/AndroidRuntime(1866): at dalvik.system.NativeStart.main(Native Method)
07-24 12:00:21.151: I/Process(1866): Sending signal. PID: 1866 SIG: 9
编辑:这是我的代码,并在第157行的注释
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.empty_button:
if (one.isEnabled()) {
oneChk = true;
if (counter == 0) {
v.setBackgroundResource(R.drawable.redsquarecircle);
counter++;
v.setTag(circle);
if (v.getTag().equals(two.getTag())
&& v.getTag().equals(three.getTag())) {
p1Wins.startAnimation(p1winner);
delayingDialog();
} else if (v.getTag().equals(four.getTag())
&& v.getTag().equals(seven.getTag())) {
p1Wins.startAnimation(p1winner);
delayingDialog();
} else if (v.getTag().equals(five.getTag())
&& v.getTag().equals(nine.getTag())) {
p1Wins.startAnimation(p1winner);
delayingDialog();
} else {
if (!oneChk || !twoChk || !threeChk || !fourChk
|| !fiveChk || !sixChk || !sevenChk
|| !eightChk || !nineChk) {
//line 157
p2.startAnimation(p2turn);
} else {
draw.startAnimation(itsdraw);
delayingDialog();
}
}
答案 0 :(得分:0)
Log Cat文件有点难以理解,但请继续关注它,您将逐渐了解要查找的内容。
首先,错误类型通常应该非常明显:
显示java.lang.NullPointerException
这告诉你它已尝试引用一些变量或视图或其他任何内容并且它为空。
接下来,您需要滚动日志cat并查找引用您文件的行号。 com.sachinda ....是死的赠品:
com.sachinda.myfirstapp.TwoPlayerActivity.onClick(TwoPlayerActivity.java:157)
您可以双击此行,它应该会打开您的文件。无论如何看这条线,都有望解决这个问题。
查看您的编辑,p2和p2turn在哪里定义?您应该确保它们是成员变量,而不是在另一个方法中定义:
int mp2 = 42; //Member vairable, available to all methods in class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int p2 = 42; // private variable, only available to onCreate
}