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

  • Home
  • SEARCH
  • 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 6187153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:00:40+00:00 2026-05-24T02:00:40+00:00

Hi All I have the following code: enter code here public class XMPPClient extends

  • 0

Hi All I have the following code:

enter code here

public class XMPPClient extends Activity {

private ArrayList<String> messages = new ArrayList<String>();
private Handler mHandler = new Handler();
private EditText mRecipient;
private EditText mSendText;
private ListView mList;
private XMPPConnection connection;
// private Chat chat;
private MultiUserChat muc;
private String to;

/**
 * Called with the activity is first created.
 */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Log.i("XMPPClient", "onCreate called");
    setContentView(R.layout.chatroom);

    mSendText = (EditText) this.findViewById(R.id.sendText);
    Log.i("XMPPClient", "mSendText = " + mSendText);
    mList = (ListView) this.findViewById(R.id.listMessages);
    Log.i("XMPPClient", "mList = " + mList);
    setListAdapter();

    setConnection();


    // Set a listener to send a chat text message
    Button send = (Button) this.findViewById(R.id.send);
    send.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // to = mRecipient.getText().toString();
            to = "nus@nus.rohit-pc";
            final String text = mSendText.getText().toString();

            Log.i("XMPPClient", "Sending text [" + text + "] to [" + to
                    + "]");
            Message msg = new Message(to, Message.Type.groupchat);
            msg.setBody(OptionsActivity.uname + ":" + text);

            try {
                muc.sendMessage(msg);
                // chat.sendMessage(text);
            } catch (XMPPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            setListAdapter();

        }
    });
    OptionsActivity.pd.dismiss();
}

 public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            this.connection.disconnect();
            finish();
        }
        return false;

        }
/**
 * Called by Settings dialog when a connection is establised with the XMPP
 * server
 * 
 * @param connection
 */
public void setConnection() {
    this.connection = ChatApis.setupConnection();
    if (connection != null) {
        connection.getChatManager();
        muc = new MultiUserChat(connection, "nus@nus.rohit-pc");
        try {
            muc.join(connection.getUser());
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        muc.addMessageListener(new PacketListener() {

            @Override
            public void processPacket(Packet arg0) {
                // TODO Auto-generated method stub
                // messages.add(fromName + ":");
                Message msg1 = (Message) arg0;
                messages.add(msg1.getBody());
                // Add the incoming message to the list view
                mHandler.post(new Runnable() {
                    public void run() {
                        // if(flag){
                        setListAdapter();
                        // }

                    }
                });


                Toast.makeText(XMPPClient.this, arg0.toString(),
                        Toast.LENGTH_SHORT).show();
                Log.i("XMPPClient", "text aaya [" + arg0.toString()
                        + "] to [" + arg0.toString() + "]");
            }
        });

    }
}

private void setListAdapter() {

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.multi_line_list_item, messages);
    adapter.notifyDataSetChanged();
    mList.setAdapter(adapter);
}

}

enter code here

can anyone point out the error?
The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.

I am really confused.

  • 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-05-24T02:00:40+00:00Added an answer on May 24, 2026 at 2:00 am

    solved by changing following statement :

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.multi_line_list_item, messages);
    

    to

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.multi_line_list_item);
            adapter.add(message);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: // Obtain the string names of all the elements
I have the following code to zip all the files and then save it
I have the following code to assign a value to all the elements of
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have the following code: class UserForm(ModelForm): email = forms.EmailField(widget = forms.TextInput(attrs ={ 'id':'email'}),
I have the following code: Tag.find_all_by_company_id(4).each.collect{|tag| tag.name }.join(,) (Essentially I'm trying to build a
I have the following code: preg_match_all('/(.*) \((\d+)\) - ([\d\.\d]+)[,?]/U', E-Book What I Didn't Learn
I have the following case: All boats have a boat type like shark ,
The rails books and web pages I've been following have all stuck to very
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions

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.