gpt4 book ai didi

android - 错误捕获错误

转载 作者:行者123 更新时间:2023-12-03 08:58:36 25 4
gpt4 key购买 nike

试图捕捉空或 0 输入。如果输入空值,应用程序崩溃,如果输入 0,它会通过错误并返回奇怪的数学!

case_cost = (EditText) findViewById(R.id.case_cost);
dilution = (EditText) findViewById(R.id.dilution);
answer =(TextView) findViewById(R.id.answer);
ounces_pc = (TextView) findViewById(R.id.ounces_pc);

Button finishBtn = (Button) findViewById(R.id.button3);
finishBtn.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Method
if (((Float.valueOf(dilution.getText().toString())) == 0) ||
(dilution.getText().equals(null))) {

String errMsg = "Missing Dilution";
answer.setText(errMsg);

} else;

调试信息:
StringToReal.invalidReal(String, boolean) line: 63  
StringToReal.parseFloat(String) line: 289
Float.parseFloat(String) line: 300
Float.valueOf(String) line: 337
UccActivity$1.onClick(View) line: 47
Button(View).performClick() line: 4102
View$PerformClick.run() line: 17063
Handler.handleCallback(Message) line: 615
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 155
ActivityThread.main(String[]) line: 5454
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not
available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 1029
ZygoteInit.main(String[]) line: 796
NativeStart.main(String[]) line: not available [native method]
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)"

最佳答案

您应该在检查值之前检查 Null。否则,当它检查 0 并且值为 Null 时,它将抛出异常。

关于android - 错误捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com