【发布时间】:2018-03-22 17:01:40
【问题描述】:
问题是每次我点击应用中的按钮时,每当我的EditText 之一或两者都为空时,应用就会崩溃。
我的想法是,我将在 EditText 中写入卡路里,称为caloriesIn,它会在 caloriesOut 中输出一个 int,这是一个文本字段。
“胖”也是如此。
问题只是总结一下,如果我在卡路里中写了一些东西,但没有在脂肪中写任何东西,或者只是在其中任何一个中都不写任何东西,应用程序就会崩溃。
我的代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText caloriesIn = (EditText) findViewById(R.id.caloriesIn);
EditText fatIn = (EditText) findViewById(R.id.fatIn);
TextView caloriesOut = (TextView) findViewById(R.id.caloriesOut);
TextView fatOut = (TextView) findViewById(R.id.fatOut);
int calories = Integer.parseInt(caloriesIn.getText().toString());
int fat = Integer.parseInt(fatIn.getText().toString());
int caloriesResult = calories;
int fatResult = fat;
caloriesOut.setText(caloriesResult + "");
fatOut.setText(fatResult + "");
}
});
}
}
崩溃报告:
03-22 17:20:02.512 22193-22193/ottolopez.healthynote I/Choreographer:跳过了 47 帧!应用程序可能在其主线程上做了太多工作。 03-22 17:20:02.556 22193-22193/ottolopez.healthynote V/View: dispatchProvideAutofillStructure(): 未布局,忽略 1073741833 的 0 个孩子 03-22 17:20:02.561 22193-22193/ottolopez.healthynote I/AssistStructure:扁平化最终辅助数据:2936 字节,包含 1 个窗口,11 个视图 03-22 17:20:05.047 22193-22193/ottolopez.healthynote D/AndroidRuntime: 关闭虚拟机 03-22 17:20:05.049 22193-22193/ottolopez.healthynote E/AndroidRuntime: 致命异常: main 进程:ottolopez.healthynote,PID:22193 java.lang.NumberFormatException:对于输入字符串:“” 在 java.lang.Integer.parseInt(Integer.java:620) 在 java.lang.Integer.parseInt(Integer.java:643) 在 ottolopez.healthynote.MainActivity$1.onClick(MainActivity.java:28) 在 android.view.View.performClick(View.java:6294) 在 android.view.View$PerformClick.run(View.java:24770) 在 android.os.Handler.handleCallback(Handler.java:790) 在 android.os.Handler.dispatchMessage(Handler.java:99) 在 android.os.Looper.loop(Looper.java:164) 在 android.app.ActivityThread.main(ActivityThread.java:6494) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
【问题讨论】:
-
添加有问题的崩溃报告。
-
我在哪里可以找到那个?
-
@Otto 应用程序崩溃后它会立即出现在 android studio 的 logcat 窗口中
-
我该如何编辑我的帖子?
-
您的问题下方有编辑按钮 ....
标签: java android crash-reports