Search code examples
androidmultithreadingtextviewdelayrunnable

cannot convert from Runnable to Thread


I get this error message "cannot convert from Runnable to Thread" This comes up for the Threat T = new Runnable(r);

Here is my code...

final String[] texts = new String[]{player, player11, player111}; //etc
            final Runnable r = new Runnable(){
                public void run(){
                    for(final int i=0;i<texts.length;i++){
                        synchronized(this){
                            wait(30000); //wait 30 seconds before changing text
                        }
                        //to change the textView you must run code on UI Thread so:
                        runOnUiThread(new Runnable(){
                            public void run(){
                                TextView t = (TextView) findViewById(R.id.textView1);
                                t.setText(texts[i]);
                            }
                        });
                    }
                }
            };
            Thread T = new Runnable(r);
            T.start();

Solution

  • You have a wrong line in your code

    Change

    Thread T = new Runnable(r);
    

    to

    Thread T = new Thread(r);