Android 不幸的是,项目已在onclick方法中关闭
这是我的照片 8是最左边的数字。勾号在点击时具有游戏状态功能。下面是代码。若我按下勾号时8在左边,项目不幸关闭。如果8出现在右侧,9个按钮中没有空格,左侧没有空格,如果我按下勾号,则项目不会关闭。请帮忙Android 不幸的是,项目已在onclick方法中关闭,android,Android,这是我的照片 8是最左边的数字。勾号在点击时具有游戏状态功能。下面是代码。若我按下勾号时8在左边,项目不幸关闭。如果8出现在右侧,9个按钮中没有空格,左侧没有空格,如果我按下勾号,则项目不会关闭。请帮忙 当8向右移动并占据27的位置时,最左边的按钮变为空,如果我按下勾号,游戏运行正常。如果8保持在左侧,如果我按下勾号,项目将关闭 这是密码 public void gameState(View view) { String button1Text = button[0].getText
当8向右移动并占据27的位置时,最左边的按钮变为空,如果我按下勾号,游戏运行正常。如果8保持在左侧,如果我按下勾号,项目将关闭 这是密码
public void gameState(View view) {
String button1Text = button[0].getText().toString();
String button2Text = button[1].getText().toString();
String button3Text = button[2].getText().toString();
String button4Text = button[3].getText().toString();
String button5Text = button[4].getText().toString();
String button6Text = button[5].getText().toString();
String button7Text = button[6].getText().toString();
String button8Text = button[7].getText().toString();
String button9Text = button[8].getText().toString();
String aa = String.valueOf(Integer.parseInt(button1Text) + Integer.parseInt(button2Text));
String bb = String.valueOf(Integer.parseInt(button4Text) + Integer.parseInt(button5Text));
String cc = String.valueOf(Integer.parseInt(button7Text) + Integer.parseInt(button8Text));
String dd = String.valueOf(Integer.parseInt(button1Text) + Integer.parseInt(button4Text));
String ee = String.valueOf(Integer.parseInt(button2Text) + Integer.parseInt(button5Text));
String ff = String.valueOf(Integer.parseInt(button3Text) + Integer.parseInt(button6Text));
if (aa.equals(button3Text)&&bb.equals(button6Text)&& cc.equals(button9Text)&&
dd.equals(button7Text)&& ee.equals(button8Text)&&ff.equals(button9Text)) {
score += 100;
numberofQuestions++;
pointstextView.setText(Integer.toString(score) + "/" + Integer.toString(numberofQuestions));
for(int j=0;j<9;j++)
{
button[j].setText("");
}
RightButton.setText("");
generateQuestion();
}
}
publicsvoid游戏状态(视图){
String button1Text=按钮[0]。getText().toString();
String button2Text=按钮[1]。getText().toString();
String button3Text=按钮[2]。getText().toString();
String button4Text=按钮[3]。getText().toString();
String button5Text=按钮[4]。getText().toString();
String button6Text=按钮[5]。getText().toString();
String button7Text=按钮[6]。getText().toString();
String button8Text=按钮[7]。getText().toString();
String button9Text=按钮[8]。getText().toString();
字符串aa=String.valueOf(Integer.parseInt(button1Text)+Integer.parseInt(button2Text));
String bb=String.valueOf(Integer.parseInt(button4Text)+Integer.parseInt(button5Text));
String cc=String.valueOf(Integer.parseInt(button7Text)+Integer.parseInt(button8Text));
String dd=String.valueOf(Integer.parseInt(button1Text)+Integer.parseInt(button4Text));
String ee=String.valueOf(Integer.parseInt(button2Text)+Integer.parseInt(button5Text));
String ff=String.valueOf(Integer.parseInt(button3Text)+Integer.parseInt(button6Text));
如果(aa.equals(button3Text)和&bb.equals(button6Text)和&cc.equals(button9Text)&&
dd.equals(按钮7文本)和ee.equals(按钮8文本)和ff.equals(按钮9文本)){
分数+=100分;
numberofQuestions++;
pointstextView.setText(Integer.toString(score)+“/”+Integer.toString(numberofQuestions));
对于(int j=0;j,从错误日志中可以看出,您试图将第717行的SecondActivity.java文件中的空字符串(即“”)转换为整数,这导致了崩溃
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:331)
at com.example.personal.numbermania.SecondActivity.gameState(SecondActivity.java:717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
检查此项并添加适当的异常处理。请发布日志,并告诉我们哪一行导致应用程序崩溃。当8向右移动并占据27的位置时,最左边的按钮变空,如果我按下勾号,游戏正常运行。如果8保持在左侧,如果我按下勾号,则项目已关闭。作为旁注,您应该为字符串使用数组。另外,如何初始化按钮数组?这是我的全部代码