我是Android开发的新手,并尝试将我的Android手机与我机器上安装的Openfire服务器集成。
我将asmack jar加载到我的库中并编写了一些代码,但是在logcat中它抛出了一个异常并且无法连接。
我的AsncTask代码如下所示。
注意=主机是我的本地主机,端口是5222,我从控制面板打开了该端口。
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
ConnectionConfiguration connConfig = null;
try {
connConfig = new ConnectionConfiguration(HOST, PORT, SERVICE_NAME);
} catch (Exception e1) {
// TODO Auto-generated catch block
Log.d("dnm", "wrong config");
e1.printStackTrace();
}
XMPPTCPConnection connection = new XMPPTCPConnection(connConfig);
try {
connection.connect();
Log.d("memo", "ok");
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("memo", "no1");
} catch (SmackException e) {
// TODO Auto-generated catch block
e.getCause();
Log.d("memo", "no2");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("memo", "no3");
e.printStackTrace();
}
return "Executed";
}
}
并且logcat是
11-29 13:54:07.156: D/memo(31420): no2
11-29 13:54:07.156: W/System.err(31420): org.jivesoftware.smack.SmackException$ConnectionException
11-29 13:54:07.166: W/System.err(31420): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:436)
11-29 13:54:07.176: W/System.err(31420): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:811)
11-29 13:54:07.176: W/System.err(31420): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
11-29 13:54:07.176: W/System.err(31420): at com.example.chattest.MainActivity$LongOperation.doInBackground(MainActivity.java:67)
11-29 13:54:07.176: W/System.err(31420): at com.example.chattest.MainActivity$LongOperation.doInBackground(MainActivity.java:1)
11-29 13:54:07.176: W/System.err(31420): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-29 13:54:07.176: W/System.err(31420): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-29 13:54:07.176: W/System.err(31420): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-29 13:54:07.176: W/System.err(31420): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-29 13:54:07.176: W/System.err(31420): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-29 13:54:07.176: W/System.err(31420): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-29 13:54:07.176: W/System.err(31420): at java.lang.Thread.run(Thread.java:856)