java - XMPP and Android Part-2 -
this question continuation of previous question though have managed remove networkonmainthreaderror, have new errors fight with,
previous question can found here: xmpp , android
this time guess probelm host name, or may service name, trying connect openfire
server.
by way need add public class settingsdialog extends dialog
menifest file
my code connection:
/** * gather xmpp settings , create xmppconnection */ public class settingsdialog extends dialog implements android.view.view.onclicklistener { private xmppclient xmppclient; public settingsdialog(xmppclient xmppclient) { super(xmppclient); this.xmppclient = xmppclient; } protected void onstart() { super.onstart(); setcontentview(r.layout.settings); getwindow().setflags(4, 4); settitle("xmpp settings"); button ok = (button) findviewbyid(r.id.ok); ok.setonclicklistener(this); } public void onclick(view v) { new networkoperation().execute(); dismiss(); }
async task
public class networkoperation extends asynctask<string, void, string> { private xmppclient xmppclient; @override protected string doinbackground(string... urls) { string host = "web.vlivetech.com"; //gettext(r.id.host); string port = "5222"; //gettext(r.id.port); string service = "web.vlivetech.com"; //gettext(r.id.service); string username = "khubaib@web.vlivetech.com"; //gettext(r.id.userid); string password = "khubaib"; //gettext(r.id.password); // create connection connectionconfiguration connconfig = new connectionconfiguration(host, integer.parseint(port),service); xmppconnection connection = new xmppconnection(connconfig); try { connection.connect(); log.i("xmppclient", "[settingsdialog] connected " + connection.gethost()); } catch (xmppexception ex) { log.e("xmppclient", "[settingsdialog] failed connect " + connection.gethost()); xmppclient.setconnection(null); } try { connection.login(username, password); log.i("xmppclient", "logged in " + connection.getuser()); // set status available presence presence = new presence(presence.type.available); connection.sendpacket(presence); xmppclient.setconnection(connection); } catch (xmppexception ex) { log.e("xmppclient", "[settingsdialog] failed log in " + username); xmppclient.setconnection(null); } return null; } @override protected void onpostexecute(string result) { } }
line on getting error in async task:
try { connection.connect(); log.i("xmppclient", "[settingsdialog] connected " + connection.gethost()); } catch (xmppexception ex) { log.e("xmppclient", "[settingsdialog] failed connect " + connection.gethost()); xmppclient.setconnection(null); }
log file
03-06 17:50:39.754: i/smackconfiguration(16410): no configuration file found 03-06 17:50:39.764: e/xmppclient(16410): [settingsdialog] failed connect null 03-06 17:50:39.764: w/dalvikvm(16410): threadid=11: thread exiting uncaught exception (group=0x40aaa210) 03-06 17:50:39.774: e/androidruntime(16410): fatal exception: asynctask #1 03-06 17:50:39.774: e/androidruntime(16410): java.lang.runtimeexception: error occured while executing doinbackground() 03-06 17:50:39.774: e/androidruntime(16410): @ android.os.asynctask$3.done(asynctask.java:278) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.futuretask.run(futuretask.java:137) 03-06 17:50:39.774: e/androidruntime(16410): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:208) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 03-06 17:50:39.774: e/androidruntime(16410): @ java.lang.thread.run(thread.java:856) 03-06 17:50:39.774: e/androidruntime(16410): caused by: java.lang.nullpointerexception 03-06 17:50:39.774: e/androidruntime(16410): @ com.example.test.networkoperation.doinbackground(networkoperation.java:33) 03-06 17:50:39.774: e/androidruntime(16410): @ com.example.test.networkoperation.doinbackground(networkoperation.java:1) 03-06 17:50:39.774: e/androidruntime(16410): @ android.os.asynctask$2.call(asynctask.java:264) 03-06 17:50:39.774: e/androidruntime(16410): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305)
if networkoperation
inside activity remove line networkoperation
or might want add constructor
(?), pass xmppclient
.execute()
private xmppclient xmppclient;
Comments
Post a Comment