问题描述
我是XMPP的新手请指导我如何使用android在xmpp中发送和接收iq数据包。这是我的代码。当我调试我的代码时它会给我这个日志错误
06-12 16:08:22.032:E / AndroidRuntime(4063):致命异常: AsyncTask#1
06-12 16:08:22.032:E / AndroidRuntime(4063):java.lang.RuntimeException:执行doInBackground时发生错误()
06-12 16:08:22.032:E / AndroidRuntime(4063):在android.os.AsyncTask $ 3.done(AsyncTask.java:299)
06-12 16:08: 22.032:E / AndroidRuntime(4063):at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-12 16:08:22.032:E / AndroidRuntime(4063): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-12 16:08:22.032:E / AndroidRuntime(4063):at java.util.concurrent.FutureTask。 run(FutureTask.java:239)
06-12 16:08:22.032:E / AndroidRuntime(4063):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)
06-12 16:08:22.032:E / AndroidRuntime(4063):at java.util.concurrent.ThreadPoolExecutor.runWorker(Thre adPoolExecutor.java:1080)
06-12 16:08:22.032:E / AndroidRuntime(4063):at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:573)
06-12 16:08:22.032:E / AndroidRuntime(4063):at java.lang.Thread.run(Thread.java:856)
06-12 16 :08:22.032:E / AndroidRuntime(4063):引起:java.lang.ClassCastException:java.lang.Object []无法强制转换为java.lang.String []
06-12 16:08:22.032:E / AndroidRuntime(4063):at com.example.xmppclient.MyTask.doInBackground(MyTask.java:1)
06-12 16:08:22.032:E / AndroidRuntime (4063):在android.os.AsyncTask $ 2.call(AsyncTask.java:287)
06-12 16:08:22.032:E / AndroidRuntime(4063):at java.util.concurrent .FutureTask.run(FutureTask.java:234)
06-12 16:08:22.032:E / AndroidRuntime(4063):... 4更多
06- 12 16:08:23.982:I / Choreographer(4063):跳过98帧!应用程序可能在其主线程上做了太多工作。
06-12 16:08:25.391:I / Choreographer(4063):跳过59帧!应用程序可能在其主线程上做了太多工作。
这是我的代码
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 =has12345; //getText(R.id.userid);
String password =123; //getText(R.id.password);
//创建连接
ConnectionConfiguration connConfig =
new ConnectionConfiguration(host,Integer.parseInt(port),service);
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
Log.i(XMPPClient,[SettingsDialog]已连接到+ connection.getHost());
} catch(XMPPException ex){
Log.e(XMPPClient,[SettingsDialog]无法连接到+ connection.getHost());
MainActivity.setConnection(null);
}
试试{
connection.login(用户名,密码);
Log.i(XMPPClient,登录为+ connection.getUser());
//将状态设置为可用
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(在场);
MainActivity.setConnection(connection);
} catch(XMPPException ex){
Log.e(XMPPClient,[SettingsDialog]无法以+ username身份登录);
MainActivity.setConnection(null);
}
返回null;
}
I am new to XMPP please guide me how to send and receive iq packets in xmpp using android. Here is my code. when i debug my code it will give me this log error
06-12 16:08:22.032: E/AndroidRuntime(4063): FATAL EXCEPTION: AsyncTask #1
06-12 16:08:22.032: E/AndroidRuntime(4063): java.lang.RuntimeException: An error occured while executing doInBackground()
06-12 16:08:22.032: E/AndroidRuntime(4063): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-12 16:08:22.032: E/AndroidRuntime(4063): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.lang.Thread.run(Thread.java:856)
06-12 16:08:22.032: E/AndroidRuntime(4063): Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]
06-12 16:08:22.032: E/AndroidRuntime(4063): at com.example.xmppclient.MyTask.doInBackground(MyTask.java:1)
06-12 16:08:22.032: E/AndroidRuntime(4063): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-12 16:08:22.032: E/AndroidRuntime(4063): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-12 16:08:22.032: E/AndroidRuntime(4063): ... 4 more
06-12 16:08:23.982: I/Choreographer(4063): Skipped 98 frames! The application may be doing too much work on its main thread.
06-12 16:08:25.391: I/Choreographer(4063): Skipped 59 frames! The application may be doing too much work on its main thread.
Here is my code
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 = "has12345"; //getText(R.id.userid); String password = "123"; //getText(R.id.password); // Create a connection ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service); XMPPConnection connection = new XMPPConnection(connConfig); try { connection.connect(); Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost()); } catch (XMPPException ex) { Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost()); MainActivity.setConnection(null); } try { connection.login(username, password); Log.i("XMPPClient", "Logged in as " + connection.getUser()); // Set the status to available Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); MainActivity.setConnection(connection); } catch (XMPPException ex) { Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username); MainActivity.setConnection(null); } return null; }
这篇关于XMPP和Android执行doInBackground()时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!