JavaRunner
JavaRunner

Reputation: 2545

Android: Thread and a NotFoundException inside of it

I have a problem with a NotFound resource exception. I'm sure that my resource-id exactly the same which I set but it fails anyway! It's an interesting thing, because the first line with the "findViewById( R.id.editText1 )" executes well and I see the label "start!" in the editText1, but the second one inside the Thread - fails with:

09-29 00:17:45.103: E/AndroidRuntime(347): android.content.res.Resources$NotFoundException: String resource ID #0x0

Can anyone help me with this sort of problem? Here is a code:

EditText editText = ( EditText ) findViewById( R.id.editText1 );
editText.setText( "start!" );

final Handler handler = new Handler();
Runnable runnable = new Runnable() {

    @Override
    public void run() {

        for (int i = 0; i <= 10; i++) {

            final int value = i;

            try {

                Thread.sleep( 1000 );

            } catch ( InterruptedException e ) {

                e.printStackTrace();

            }

           handler.post( new Runnable() {

               @Override
               public void run() {

                   EditText editText = ( EditText ) findViewById( R.id.editText1 );
                   editText.setText( value );

               }

           } );

        }

    }

};

Thread thread = new Thread( runnable );
thread.start();

Upvotes: 0

Views: 90

Answers (1)

Jason Robinson
Jason Robinson

Reputation: 31283

value is an integer value. Passing an integer into the setText method will attempt to find a String from your strings.xml file by resource ID. If you want to display a numeral, you'll need to parse it as a String: Integer.toString(value)

Upvotes: 1

Related Questions