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.
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:
myTextView.setText("" + 1); // Or whatever number
The error happens because TextView
has another method: setText(int resid)
. This method looks for a resource id, which does not exist in your case. Link
You are trying to set the content text of a TextView with an integer value.
The issue is that the method you are using is expecting a resource id.
You need to make a String out of your integer before putting it in the TextView :
textView.setText(Integer.toString(7));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With