Hello all!
I'm going to implement a simple chat application. I designed to
introduce an interface called TextReceiveListener that expose just one
method:
void receive(String message)
Doing so, I wrote this:
public class SChat extends Activity implements TextReceiveListener {
...
public void receive(String message) {
setContentView(R.layout.main);
String s = txtChatHistory.getText().toString();
s += message + "\n";
txtChatHistory.setText(s);
}
...
}
Essentially, receive() method is called by a listener thread whenever
a message arrives, but... I obtain the following exception stacktrace:
android.view.ViewRoot$CalledFromWrongThreadException: Only the
original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2440)
at android.view.ViewRoot.clearChildFocus(ViewRoot.java:1370)
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:494)
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:494)
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:494)
at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:
2154)
at android.view.ViewGroup.removeAllViews(ViewGroup.java:2100)
at com.android.internal.policy.impl.PhoneWindow.setContentView
(PhoneWindow.java:307)
at android.app.Activity.setContentView(Activity.java:1626)
at it.unitn.schat.SChat.receive(SChat.java:106)
at it.unitn.schat.security.impl.CryptoInterfaceImpl.receive
(CryptoInterfaceImpl.java:184)
at it.unitn.schat.core.impl.NetworkInterfaceImpl$Service.run
(NetworkInterfaceImpl.java:325)
Do I miss something? O_o Why my thread is "wrong"?
Thank you in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---