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 7780297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:51:07+00:00 2026-06-01T18:51:07+00:00

I’m trying to implement a chat client for Android which connects to google talk

  • 0

I’m trying to implement a chat client for Android which connects to google talk service. I have done most of it, I connect to the server, I get contacts (and show them in a ListView) and I open a new Activity when clicking a contact name on the list where the messages are send and received. My problem is that now I’m trying to get the Presence of the contacts of a user’s account. I have written this code but it is not working and I’m not able to discover why. Any help is appreciated.

Button connect = (Button) findViewById(R.id.connect);
    connect.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            String username = getTheText(R.id.UserName);
            String password = getTheText(R.id.Password);

            login(username, password);
            try {
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
      }
            roster = connection.getRoster();

            entries = roster.getEntries();
            arrayOfEntries = new ArrayList<RosterEntry>(entries);
            searchedContacts = GetSearchContacts();\\This method is the one who is not working correctly

            try{

                launchNextActivity();

            }catch(Exception e){
                e.printStackTrace();

             }

        }


     });
    /*
 * Asigna los datos del ArrayList de RosterEntry al ArraList de SearchContacts
 */

private ArrayList<SearchContacts> GetSearchContacts(){
    ArrayList<SearchContacts> results = new ArrayList<SearchContacts>();
      \\The class SearchContacts is an own class very simple with a constructor which assigns 4 parameters to the objects of the class, and getters and setters for every parameter.
    for (RosterEntry r : arrayOfEntries){
        SearchContacts sc = new SearchContacts(null, null,null,null);
        sc.setNick(r.getName());
        sc.setEmail(r.getUser());
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
        prs = roster.getPresence(r.getUser());
        Presence.Mode presence2 = prs.getMode();
        status = ConvierteEnumToString(presence2);
        sc.setFirstSentence(status);
        results.add(sc);


    }
    return results;

}

\*
     *
     *\ 
private void ConvierteEnumToString(Presence.Mode pm){

    switch(pm){
    case available:
        Log.i(LOGTAG,"Case Available");
        status= "Available";
        break;
    case away:
        Log.i(LOGTAG,"Case away");
        status= "Away";
        break;
    case chat:
        Log.i(LOGTAG,"Case chat");
        status= "chat";
        break;
    case dnd:
        Log.i(LOGTAG,"Case dnd");
        status= "Do not disturb";
        break;
    case xa:
        Log.i(LOGTAG,"Case xa");
        status= "Unavailable";
                    break;
            default:
                    Log.i(LOGTAG,"Invalid status");
                    status="Invalid";
                    break;

    }




}

If I change the attribute of this line:
String status = ConvierteEnumToString(presence2);
and I put directly Presence.Mode.available, it assigns the status available to all of my contacts but it works correctly. If I let it as it is in the code above I get an Exception like this:

04-10 23:11:02.866: W/dalvikvm(1722): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-10 23:11:02.886: E/AndroidRuntime(1722): FATAL EXCEPTION: main
04-10 23:11:02.886: E/AndroidRuntime(1722): java.lang.NullPointerException
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.chat.Login.GetSearchContacts(Login.java:164)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.chat.Login.access$1(Login.java:153)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.chat.Login$1.onClick(Login.java:81)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.view.View.performClick(View.java:2485)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.view.View$PerformClick.run(View.java:9080)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.os.Handler.handleCallback(Handler.java:587)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.os.Looper.loop(Looper.java:123)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at java.lang.reflect.Method.invoke(Method.java:507)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-10 23:11:02.886: E/AndroidRuntime(1722):     at dalvik.system.NativeStart.main(Native Method)

With the difference that I sometimes get One user status and then the Exception occurs and sometimes no status is got at all.
Thank you very much for your help!

  • 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-01T18:51:08+00:00Added an answer on June 1, 2026 at 6:51 pm

    I have discovered the problem. I add the solution here to whom it may concern.

    The problem was that when this line is executed:

    Presence.Mode presence2 = prs.getMode();

    one of the possible values that presence2 can get is null. So you are passing a null variable to a try/catch structure which was waiting for a Presence.Mode presence variable… Thats why a NullPointerException is got.

    I have added an if clause just after that line which test if the variable presence2 is equals to null and if it happens it changes it somehow. I suppose it can also be done surrounding the line with a try/catch structure and treating the NullPointerException somehow.

    I hope it can help to anyone at least to not waste time thinking a solution for this!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.