0

I want to get list of register user but i am getting a null pointer exception when i call searchForm.createAnswerForm().

I am using openfire local server and connection is already established and just want to get the list of users. search service in serve is enabled

Here is my code:

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);         
};

}

this is my error log

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):
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Fallak Asad
  • 368
  • 4
  • 18
  • You don't check if searchForm is null before you try to use it. Read the documentation for getSearchForm to understand why it returns null. – Simon Jan 18 '14 at 09:42
  • yes it was the problem with the getSearchForm and i solved it by the help of following post http://stackoverflow.com/questions/5910219/getsearchform-returns-null-when-using-usersearch-in-xmpp-with-asmack and thanks @Simon for indicating the problem – Fallak Asad Jan 18 '14 at 11:11

0 Answers0