[英]ResourceNotFoundException - String resource ID
07-25 10:15:37.960: E/AndroidRuntime(8661): android.content.res.Resources$NotFoundException: String resource ID #0x7
07-25 10:15:37.960: E/AndroidRuntime(8661): at android.content.res.Resources.getText(Resources.java:230)
Good day to all. 大家好日子。
I am trying to display an integer value in a Text View and the above error shows up in LogCat. 我试图在文本视图中显示一个整数值,上面的错误显示在LogCat中。
There are other similar posts about this issue; 关于这个问题还有其他类似的帖子; like this , this , and this , but none of the solutions worked for me. 像这样 , 这个 , 这个 ,但没有一个解决方案适合我。
Any other ideas of what the problem might be? 关于问题可能是什么的任何其他想法?
Edited for code: 编辑代码:
private static Button btnCancel;
private static Button btnConfirm;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtRoomNumber = (EditText)findViewById(R.id.txtRoomNumber);
btnCancel = (Button)findViewById(R.id.btnCancel);
btnConfirm = (Button)findViewById(R.id.btnConfirm);
btnCancel.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
System.exit(0);
}
});
btnConfirm.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
int rmNo = getRoomNumberValue();
txtTesting.setText(rmNo);
}
});
}
private int getRoomNumberValue()
{
int temp = 0;
try
{
temp = Integer.parseInt(txtRoomNumber.getText().toString());
}
catch(Exception e)
{
e.printStackTrace();
}
return temp;
}
If you are trying to display an integer value in a TextView
, use this: 如果您尝试在TextView
显示整数值,请使用以下命令:
myTextView.setText("" + 1); // Or whatever number
The error happens because TextView
has another method: setText(int resid)
. 发生错误是因为TextView
有另一种方法: setText(int resid)
。 This method looks for a resource id, which does not exist in your case. 此方法查找资源ID,在您的情况下不存在。 Link 链接
You are trying to set the content text of a TextView with an integer value. 您正在尝试使用整数值设置TextView的内容文本。
The issue is that the method you are using is expecting a resource id. 问题是您使用的方法是期望资源ID。
You need to make a String out of your integer before putting it in the TextView : 在将它放入TextView之前,需要从整数中生成一个String:
textView.setText(Integer.toString(7));
将整数更改为字符串
textview.setText(String.valueOf(valueofint));
To convert integer to string use 要将整数转换为字符串使用
int x=10;
Integer.toString(x);
That will solve your problem 这将解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.