我想获取注册用户列表,但是当我调用时出现空指针异常searchForm.createAnswerForm()
。
我正在使用openfire
本地服务器并且连接已经建立并且只想获取用户列表。服务中的搜索服务已启用
这是我的代码:
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.search.UserSearchManager;
import android.util.Log;
public class UserSearch {
private static final String TAG = "UserSearch";
public static final String SERVER="192.168.1.5";
public static void start() throws Exception
{
UserSearchManager search = new UserSearchManager(MyService.getConnection());
Log.i(TAG, "hear1");
Form searchForm = search.getSearchForm("search."+ SERVER);
Log.i(TAG, "hear2");
Form answerForm = searchForm.createAnswerForm();
Log.i(TAG, "hear3");
answerForm.setAnswer("Username", true);
Log.i(TAG, "hear4");
answerForm.setAnswer("search", "*");
search.getSearchResults(answerForm, "search."+ SERVER);
};
}
这是我的错误日志
01-18 08:59:06.744: I/UserSearch(1675): hear1
01-18 08:59:06.903: I/UserSearch(1675): hear2
01-18 08:59:06.903: W/System.err(1675): java.lang.NullPointerException
01-18 08:59:06.903: W/System.err(1675): at org.codeandmagic.android.asmack_test.UserSearch.start(UserSearch.java:27)
01-18 08:59:06.915: W/System.err(1675): at org.codeandmagic.android.asmack_test.FriendListActivity.onCreate(FriendListActivity.java:48)
01-18 08:59:06.915: W/System.err(1675): at android.app.Activity.performCreate(Activity.java:5104)
01-18 08:59:06.915: W/System.err(1675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-18 08:59:06.915: W/System.err(1675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-18 08:59:06.924: W/System.err(1675): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)
01-18 08:59:06.924: W/System.err(1675): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
01-18 08:59:06.944: W/System.err(1675): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
01-18 08:59:06.954: W/System.err(1675): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
01-18 08:59:06.954: W/System.err(1675): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
01-18 08:59:06.954: W/System.err(1675): at android.widget.TabHost.addTab(TabHost.java:240)
01-18 08:59:06.964: W/System.err(1675): at org.codeandmagic.android.asmack_test.menuActivity.onCreate(menuActivity.java:39)
01-18 08:59:06.964: W/System.err(1675): at android.app.Activity.performCreate(Activity.java:5104)
01-18 08:59:06.964: W/System.err(1675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-18 08:59:06.984: W/System.err(1675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-18 08:59:06.984: W/System.err(1675): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-18 08:59:07.004: W/System.err(1675): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-18 08:59:07.014: W/System.err(1675): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-18 08:59:07.014: W/System.err(1675): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 08:59:07.014: W/System.err(1675): at android.os.Looper.loop(Looper.java:137)
01-18 08:59:07.034: W/System.err(1675): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-18 08:59:07.034: W/System.err(1675): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 08:59:07.054: W/System.err(1675): at java.lang.reflect.Method.invoke(Method.java:511)
01-18 08:59:07.066: W/System.err(1675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 08:59:07.074: W/System.err(1675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 08:59:07.086: W/System.err(1675): at dalvik.system.NativeStart.main(Native Method)
01-18 08:59:07.094: I/System.out(1675): 0 buddy(ies):