java - Android Stack NullPointer on selecting a suggestion in Search Widget -


i using search widget auto completed in home screen. auto complete functionally working fine when select suggestion app crashing weird nullpointerexception. spent enough time on googling not find clue. pasting code below.

 @override     public boolean oncreateoptionsmenu(menu menu) {          log.e("conversion", "onceateoption menu started");         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu, menu);          // searchview , set searchable configuration         searchmanager searchmanager = (searchmanager) getsystemservice(context.search_service);         searchview searchview = (searchview) menu.finditem(r.id.menu_search).getactionview();         // sets our icon search icon on title bar        imageview searchhinticon = (imageview) findviewbyid(searchview,               "android:id/search_button");        searchhinticon.setimageresource(r.drawable.searchicon);          // set hint text color         int id = searchview.getcontext().getresources().getidentifier("android:id/search_src_text", null, null);         autocompletetextview searchtextview = (autocompletetextview) searchview.findviewbyid(id);         searchtextview.settextcolor(color.black);           // set hint in search widget         searchview.setqueryhint("enter conversion");          log.e("conversion", "before setting auto suggestions");         // set auto suggestions         arraylist<string> list = new arraylist<string>(arrays.aslist(suggestionlist));         autosuggestionadapter autosuggestionadapter = new autosuggestionadapter(this,               r.layout.autosuggestion_layout, list);         //arrayadapter<string> autosuggestionadapter = new arrayadapter<string>(this,           //      android.r.layout.simple_dropdown_item_1line, suggestionlist);         ((autocompletetextview) searchtextview).setadapter(autosuggestionadapter);         ((autocompletetextview) searchtextview).setthreshold(3);         // assumes current activity searchable activity         searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname()));         searchview.seticonifiedbydefault(true); // not iconify widget; expand default         log.e("conversion", "autosuggestions set");          return true;     } 

menu item is

<item         android:id="@+id/menu_search"         android:icon="@drawable/searchicon"         android:title="@string/action_search"         android:showasaction="always"         android:actionviewclass="android.widget.searchview"         /> 

and exception log is:

01-16 19:47:22.550 17995-17995/? e/androidruntime: java.lang.nullpointerexception 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.searchview.launchsuggestion(searchview.java:1387) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.searchview.onitemclicked(searchview.java:1303) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.searchview.access$1800(searchview.java:92) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.searchview$9.onitemclick(searchview.java:1327) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.autocompletetextview.performcompletion(autocompletetextview.java:931) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.autocompletetextview.access$400(autocompletetextview.java:98) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.autocompletetextview$dropdownitemclicklistener.onitemclick(autocompletetextview.java:1235) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.adapterview.performitemclick(adapterview.java:298) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.abslistview.performitemclick(abslistview.java:1150) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.listview.performitemclick(listview.java:4397) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.abslistview$performclick.run(abslistview.java:2985) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.widget.abslistview$1.run(abslistview.java:3671) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.os.handler.handlecallback(handler.java:615) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.os.handler.dispatchmessage(handler.java:92) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.os.looper.loop(looper.java:155) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ android.app.activitythread.main(activitythread.java:5520) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ java.lang.reflect.method.invokenative(native method) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ java.lang.reflect.method.invoke(method.java:511) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1058) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:825) 01-16 19:47:22.550 17995-17995/? e/androidruntime:     @ dalvik.system.nativestart.main(native method) 01-16 19:47:22.560 399-4972/? e/embeddedlogger: app crashed! process: com.example.app.myapplication 

but there no possibility of getting nullpointer when checked android class code.

private intent createintent(string action, uri data, string extradata, string query,         int actionkey, string actionmsg) {     // build intent     intent intent = new intent(action);     intent.addflags(intent.flag_activity_new_task);     // need clear_top avoid reusing old task has other activities     // on top of 1 want. don't want in in-app search though,     // can destructive activity stack.     if (data != null) {         intent.setdata(data);     }     intent.putextra(searchmanager.user_query, muserquery);     if (query != null) {         intent.putextra(searchmanager.query, query);     }     if (extradata != null) { /**** line number 1387 null pointer in line ******************/         intent.putextra(searchmanager.extra_data_key, extradata);     }     if (mappsearchdata != null) {         intent.putextra(searchmanager.app_data, mappsearchdata);     }     if (actionkey != keyevent.keycode_unknown) {         intent.putextra(searchmanager.action_key, actionkey);         intent.putextra(searchmanager.action_msg, actionmsg);     }     intent.setcomponent(msearchable.getsearchactivity());     return intent; } 

any thoughts??

first, searchview's code on code not of test device's version line number not match. should occur in launchsuggestion() method log says, not createintent() posted.

the problem not in android's framework code, crashed while processing suggestion list provided, met null data in list.

from code, following part making suggestion list:

// set auto suggestions arraylist<string> list = new arraylist<string>(arrays.aslist(suggestionlist)); autosuggestionadapter autosuggestionadapter = new autosuggestionadapter(this,     r.layout.autosuggestion_layout, list); 

in here, adapter grabs data suggestionlist, if 1 of element null can lead nullpointerexception.

i don't know in suggestionlist, can sure caused null in it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -