简体   繁体   中英

XMPP chat in Android

This is my Roster class.

public class RosterList extends Activity {
/** Called when the activity is first created. */
Variables var = new Variables();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.roster);

    Roster roster = var.connection.getRoster();
    Collection<RosterEntry> entries = roster.getEntries();
    TextView tv;

    for (RosterEntry r : entries) {
        tv = (TextView)findViewById(R.id.rosterString);
        tv.append(r.getUser().toString()+ "\n");
    }
  }
}

I have created a separate class for hold variables which is Variables . There i have created my XMPPConnection -variable and others. But there are some runtime errors in this code.

Error occurs when roster -object is created. How can i access the XMPPConnection for this class? Why can't i create an instance of the Variables class and access connection variable ?

Static variables solved the problem. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM