字符串不转换为 int
String doesnt convert to int
我正在尝试获取 edittext 的文本并将其转换为 int,但我遇到了这个错误:
android.content.res.Resources$NotFoundException: String resource ID #0x5
代码很简单:
temp=String.valueOf(editm.getText());
minput = Integer.parseInt(temp);
Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();
temp是字符串变量,minput是int类型。
我也试过 .tostring() & Integer.valueof()
试试这个会解决问题:
temp=editm.getText().toString().trim();
minput = Integer.parseInt(temp);
Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();
更新:
它可以为你的 toast 发出:(尝试在你的 toast 消息中将 int 转换为字符串)
Toast.makeText(this, minput.toString(), Toast.LENGTH_SHORT).show();
您正在尝试将某些内容转换为 int,然后尝试调用 Toast.makeText(Context context, int resId, int duration)
。如果第二个参数是一个int,它应该是一个资源id。
问题是您是否希望将其转换为 int。现在,您使用它的值只是为了在 toast 消息上显示它,而这又需要传递一个字符串。
Toast.makeText(this, String.valueOf(minput), Toast.LENGTH_SHORT).show();
我正在尝试获取 edittext 的文本并将其转换为 int,但我遇到了这个错误:
android.content.res.Resources$NotFoundException: String resource ID #0x5
代码很简单:
temp=String.valueOf(editm.getText());
minput = Integer.parseInt(temp);
Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();
temp是字符串变量,minput是int类型。 我也试过 .tostring() & Integer.valueof()
试试这个会解决问题:
temp=editm.getText().toString().trim();
minput = Integer.parseInt(temp);
Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();
更新:
它可以为你的 toast 发出:(尝试在你的 toast 消息中将 int 转换为字符串)
Toast.makeText(this, minput.toString(), Toast.LENGTH_SHORT).show();
您正在尝试将某些内容转换为 int,然后尝试调用 Toast.makeText(Context context, int resId, int duration)
。如果第二个参数是一个int,它应该是一个资源id。
问题是您是否希望将其转换为 int。现在,您使用它的值只是为了在 toast 消息上显示它,而这又需要传递一个字符串。
Toast.makeText(this, String.valueOf(minput), Toast.LENGTH_SHORT).show();