Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9105507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:07:30+00:00 2026-06-17T02:07:30+00:00

Im making a simple chat via Client/Server, and When I send the message to

  • 0

Im making a simple chat via Client/Server, and When I send the message to the server it shows the ListView Bubble perfectly. But when I send one from the server and the client receives it it tries to execute addItems() and it shuts down. I tried everything. I know it’s because i cant change the UI from Asynctask but i’m new to Android/Java and I don’t know what to DOOOOOOOO!! HELP PLEASEEEE!!!!!

***MY LOG CAT** 01-08 18:32:41.023: E/AndroidRuntime(1242): FATAL EXCEPTION: AsyncTask #1
01-08 18:32:41.023: E/AndroidRuntime(1242): java.lang.RuntimeException: An error occured while executing doInBackground()
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.lang.Thread.run(Thread.java:856)
01-08 18:32:41.023: E/AndroidRuntime(1242): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4609)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:835)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.View.requestLayout(View.java:15129)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.View.requestLayout(View.java:15129)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.View.requestLayout(View.java:15129)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.View.requestLayout(View.java:15129)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:292)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.view.View.requestLayout(View.java:15129)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.AbsListView.requestLayout(AbsListView.java:1932)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:813)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6051)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.widget.ArrayAdapter.add(ArrayAdapter.java:182)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at com.i911.emergency.response.DiscussArrayAdapter.add(DiscussArrayAdapter.java:26)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at com.i911.emergency.response.HelloBubblesActivity.addItems(HelloBubblesActivity.java:148)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at com.i911.emergency.response.HelloBubblesActivity.access$0(HelloBubblesActivity.java:147)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at com.i911.emergency.response.HelloBubblesActivity$TcpClientTask.doInBackground(HelloBubblesActivity.java:116)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at com.i911.emergency.response.HelloBubblesActivity$TcpClientTask.doInBackground(HelloBubblesActivity.java:1)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-08 18:32:41.023: E/AndroidRuntime(1242):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-08 18:32:41.023: E/AndroidRuntime(1242):     ... 5 more

Here is my code:

  package com.ChatWithMe;

  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
        import java.net.Socket;
  import java.net.UnknownHostException;
  import com.ChatWithMe.OneComment;
  import android.app.Activity;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.View.OnKeyListener;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;

  public class HelloBubblesActivity extends Activity {
private com.ChatWithMe.DiscussArrayAdapter adapter;
private ListView lv;
private EditText editText1;
public Socket s;
public BufferedWriter out;
public BufferedReader in;
public TextView i911Log;
public EditText DataToSend;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_discuss);
    lv = (ListView) findViewById(R.id.listView1);
    adapter = new DiscussArrayAdapter(getApplicationContext(), R.layout.listitem_discuss);
    lv.setAdapter(adapter);
    new TcpClientTask().execute();

    editText1 = (EditText) findViewById(R.id.editText1);
    editText1.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                adapter.add(new OneComment(false, "User: " + editText1.getText().toString()));
                adapter.add(new OneComment(true, "User: " + editText1.getText().toString()));
                try {
                out.write("TXT:" + editText1.getText().toString());
                out.flush();
                } catch (UnknownHostException e) {
                     e.printStackTrace();
                     adapter.add(new OneComment(false, "Error Sending: " + editText1.getText().toString()));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    adapter.add(new OneComment(false, "Error Sending: " + editText1.getText().toString()));
                    Log.i("TcpClient", "Button Clicked, but IOException Occured");
                }

                editText1.setText("");
                return true;
            }
            return false;
        }
    });

}

class TcpClientTask extends AsyncTask<Void, Void, Void> {
    private static final int TCP_SERVER_PORT = 1234;
    private boolean error = false;
    Boolean SocketStarted = false;
    private BufferedReader in;
    protected Void doInBackground(Void... arg0) {
        try {
            Socket s = new Socket("10.0.2.2", TCP_SERVER_PORT);
            //10.0.2.2
                in = new BufferedReader(new InputStreamReader(s.getInputStream()));
                out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

            //send output msg
            String outMsg = "VER:Android,ID:1038263,SND:1,VDO:1,GPS:1,";
            out.write(outMsg);
            out.flush();
            String outMsg2 = com.ChatWithMe.MainActivity.GPSTracker.toString();
            out.write(outMsg2);
            out.flush();
            Log.i("TcpClient", "sent: " + outMsg);

            String WhatsIN = in.readLine();
            while(WhatsIN!=null){
            String inMsg = in.readLine() + System.getProperty("line.separator");
            Log.i("TcpClient", "received: " + inMsg);


            String inMsg3 = inMsg.substring(1,inMsg.length() - 1);
            Log.i("Info", "info: " + inMsg3);

            if (inMsg3.equals("GPSX")) {
                String GPSTracking = com.ChatWithMe.MainActivity.GPSTracker.toString();
                Log.i("GPSX", "Sent:" + GPSTracking.toString());
                out.write(GPSTracking);
                out.flush();
            }

            // Check Commands
            String CmdCheck = inMsg3.substring(0,4);
            if (CmdCheck.equals("TXT:")) {
           String SpitItOut = inMsg3.substring(4, inMsg3.length() - 1); 
           Log.i("SpitItOut", "Msg:" + SpitItOut.toString());

          //ERROR IS HERE
           addItems();
          //ERROR IS HERE   
            }

            } 

        } catch (UnknownHostException e) {
            error = true;
            e.printStackTrace();
        } catch (IOException e) {
            error = true;
            e.printStackTrace();
        } 

        return null;
    }

    protected void onPostExecute() {
        if(error) {
            // Something bad happened

        }
        else {
            // Success

        }
    }


}

private void addItems() {
    adapter.add(new OneComment(true, "Hello bubbles!"));
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:07:32+00:00Added an answer on June 17, 2026 at 2:07 am

    Read about Async Tasks here . Basicaly you have onPostExecute() method that runs on UI thread and you should pass results from doInBackground() to it and modify UI or whatever you have to do in main thread. So your addItems() method produces error since you are trying to change your adapter from background thread. Move it in onPostExecute() and it should fix your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making simple one on server side & one on client side application
I'm making a simple client server chat application. I want to be able to
I'm making simple XMPP client using Jabber-Net. To send simple message i'm using a
I am making a TCP chat server from a simple tutorial I found and
I'm making simple php chat, and i need to refresh messages in one div.I
I'm making a chat room with a text file. Very simple, but I don't
I'm making a small chat application. I got to the point where one client
I am making a simple chat GUI and I have written both a server
I am making a chat room using simple socket-socket connections. I have a server
I am making simple connection between two table - first one called users has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.