5
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;
} 
Community
  • 1
  • 1
ClaireG
  • 1,244
  • 2
  • 11
  • 23

4 Answers4

16

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

Vikram
  • 51,313
  • 11
  • 93
  • 122
3

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));
njzk2
  • 38,969
  • 7
  • 69
  • 107
2

Change your Integer to String

textview.setText(String.valueOf(valueofint));
Oli
  • 3,496
  • 23
  • 32
2

To convert integer to string use

int x=10;
Integer.toString(x);

That will solve your problem

Masoud Dadashi
  • 1,044
  • 10
  • 11