1

今天。我正在使用 xmpp Api smack 开发一个 android 应用程序,我想在 openfire 服务器上获取聊天室,但是当我调用以下函数时:

Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(ClientConServer.connection,"conference." + ClientConServer.connection.getServiceName());

我收到以下错误:

08-12 15:53:50.754: E/AndroidRuntime(2897): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multichat/com.example.multichat.QuestionsList}: java.lang.NullPointerException
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.os.Looper.loop(Looper.java:137)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at java.lang.reflect.Method.invoke(Method.java:525)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at dalvik.system.NativeStart.main(Native Method)
08-12 15:53:50.754: E/AndroidRuntime(2897): Caused by: java.lang.NullPointerException
08-12 15:53:50.754: E/AndroidRuntime(2897):     at org.jivesoftware.smackx.muc.MultiUserChat.getHostedRooms(MultiUserChat.java:288)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at com.example.multichat.QuestionsList.onCreate(QuestionsList.java:78)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.Activity.performCreate(Activity.java:5133)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-12 15:53:50.754: E/AndroidRuntime(2897):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-12 15:53:50.754: E/AndroidRuntime(2897):     ... 11 more

我尽力在谷歌搜索这个问题,有人给出这样的建议: 在此处输入链接描述

但他们的方法对我不起作用?我需要你的帮助!

4

2 回答 2

0

这可能是一个初始化问题。

java Smack 在启动时读取 META-INF/smack-config.xml 并加载其中列出的类(从而执行这些类中的静态块)。Android asmack 需要一些变通方法来获得正确的初始化。

另请参阅无法从 Android 上的 xmpp 服务器获取公共房间列表?

于 2013-08-16T14:32:20.413 回答
0

放入<activity android:name=".QuestionsList"/>您的AndroidManifest.xml(修改以适合您的活动所在的位置)

于 2013-08-13T06:01:45.867 回答