Android: Executor.execute fails for some reason

113 views Asked by At

In the run() method of a thread, earlier I had this code snippet:

updateConversationHandler.post(new updateUIThread(read,write,this.clientSocket,input,out));

It used to work. But when I call it using Executors, it fails:

                    executor = Executors.newFixedThreadPool(5);
                    executor.execute(new updateUIThread(read,write,this.clientSocket,input,out));

There's no response with the above code.

Any suggestions ??

3

There are 3 answers

2
Alexander On

Because your executor knows nothing about updateConversationHandler

0
Ravind Maurya On

use like this: make your constructor according to your parameter:

class updateUIThread implements Runnable { private String msg;

        public updateUIThread(String str) {
            this.msg = str;
        }

        @Override
        public void run() {
            text.setText(text.getText().toString()+"Client Says: "+ msg + "\n");
        }
    }
0
Abhishek On

OK problem solved. Removed all instances of 'Toasts' and 'text.setText()'. Works properly now.

The Android team must make a list of such errors and list them at their site. Something like "Error message -- Possible Cause -- Solution". That way.