Fragment method and socket.io

Posted by Tolgay Toklar on Stack Overflow See other posts from Stack Overflow or by Tolgay Toklar
Published on 2014-08-19T16:07:52Z Indexed on 2014/08/19 16:20 UTC
Read the original article Hit count: 184

Filed under:

I have a method,this method updates an array list in fragment.I can call this method in main activity like this

public void getFromUser(String message) {
    addMessageToFragment("ok");
}
public void addMessageToFragment(String message) {
    Log.w("Step 1",message);
    frgObj.addMessageToList("asd");

}

getFromUser is calling from fragment(when user presses the button) this is working as well.But I am using socket.io in my app,when I try to call this method from socket.io,app is not working.

public void on(String event, IOAcknowledge ack, Object... args) {
     try{
          addMessageToFragment("ok");
      } catch (JSONException e) {}

}

When this callback function calls,app is giving this errors:

08-19 11:57:24.813: W/System.err(4962): io.socket.SocketIOException: Exception was thrown in on(String, JSONObject[]).
08-19 11:57:24.813: W/System.err(4962): Message was: 5:::{"name":"listele","args":[{"mesaj":"123","gonderen":"781722165-tolgay007-DKSMIcIYGahPuKXriM83","alici":"tolgay007","blck_id":"781722165-tolgay007","out_username":"Anony-781722","ars_status":1,"longinf":"3aqghef","a_status":1}]}
08-19 11:57:24.813: W/System.err(4962):     at io.socket.IOConnection.transportMessage(IOConnection.java:702)
08-19 11:57:24.813: W/System.err(4962):     at io.socket.WebsocketTransport.onMessage(WebsocketTransport.java:82)
08-19 11:57:24.813: W/System.err(4962):     at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:361)
08-19 11:57:24.813: W/System.err(4962):     at org.java_websocket.WebSocketImpl.deliverMessage(WebSocketImpl.java:565)
08-19 11:57:24.813: W/System.err(4962):     at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:331)
08-19 11:57:24.813: W/System.err(4962):     at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:152)
08-19 11:57:24.813: W/System.err(4962):     at org.java_websocket.client.WebSocketClient.interruptableRun(WebSocketClient.java:247)
08-19 11:57:24.823: W/System.err(4962):     at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:193)
08-19 11:57:24.823: W/System.err(4962):     at java.lang.Thread.run(Thread.java:841)
08-19 11:57:24.823: W/System.err(4962): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6094)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:2800)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:650)
08-19 11:57:24.823: W/System.err(4962):     at android.view.View.setFlags(View.java:8878)
08-19 11:57:24.823: W/System.err(4962):     at android.view.View.setFocusableInTouchMode(View.java:6114)
08-19 11:57:24.823: W/System.err(4962):     at android.widget.AdapterView.checkFocus(AdapterView.java:718)
08-19 11:57:24.823: W/System.err(4962):     at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:813)
08-19 11:57:24.823: W/System.err(4962):     at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6280)
08-19 11:57:24.823: W/System.err(4962):     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
08-19 11:57:24.823: W/System.err(4962):     at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
08-19 11:57:24.823: W/System.err(4962):     at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
08-19 11:57:24.823: W/System.err(4962):     at com.impact.ribony.ConversationFragment.addMessageToList(ConversationFragment.java:91)
08-19 11:57:24.823: W/System.err(4962):     at com.impact.ribony.MainActivity.addMessageToFragment(MainActivity.java:344)
08-19 11:57:24.823: W/System.err(4962):     at com.impact.ribony.MainActivity$2.on(MainActivity.java:183)
08-19 11:57:24.823: W/System.err(4962):     at io.socket.IOConnection.on(IOConnection.java:908)
08-19 11:57:24.883: W/System.err(4962):     at io.socket.IOConnection.transportMessage(IOConnection.java:697)

I didn't understand this error.What can be cause this error ?

© Stack Overflow or respective owner

Related posts about android