gpt4 book ai didi

java.lang.NumberFormatException : Invalid int: "android. support.v7.internal.widget.TintEditText

转载 作者:行者123 更新时间:2023-12-02 05:03:13 25 4
gpt4 key购买 nike

我有代码将两个文本框中的两个数字相加。

    public void sumNumbers(View v){
EditText input1 = (EditText) findViewById(R.id.input1);
int calc1 = Integer.parseInt(String.valueOf(input1));
EditText input2 = (EditText) findViewById(R.id.input2);
int calc2 = Integer.parseInt(String.valueOf(input2));
int total = calc1 + calc2;
String result = String.valueOf(total);
EditText output1 = (EditText)findViewById(R.id.output);
output1.setText(result);
}

但是,当我启动应用程序并按下按钮时,我崩溃了:

Caused by: java.lang.NumberFormatException: Invalid int: "android.support.v7.internal.widget.TintEditText{b412b358 VFED..CL ........ 292,60-392,100 #7f080041 app:id/input1}"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at java.lang.Integer.parseInt(Integer.java:332)
at com.eren.addingmachine.MainActivity.sumNumbers(MainActivity.java:22)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at android.view.View$1.onClick(View.java:3628)
            at android.view.View.performClick(View.java:4240)
            at android.view.View$PerformClick.run(View.java:17721)
            at android.os.Handler.handleCallback(Handler.java:730)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

帮忙?

最佳答案

请粘贴以下工作代码。我刚刚运行并检查了它。

public void sumNumbers(View v){
EditText input1 = (EditText) findViewById(R.id.input1);
int calc1 = Integer.parseInt(String.valueOf(input1.getText()));
EditText input2 = (EditText) findViewById(R.id.input2);
int calc2 = Integer.parseInt(String.valueOf(input2.getText()));
int total = calc1 + calc2;
String result = String.valueOf(total);
EditText output1 = (EditText)findViewById(R.id.output);
output1.setText(result);
}

关于java.lang.NumberFormatException : Invalid int: "android. support.v7.internal.widget.TintEditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28047367/

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