1
這裏是代碼越來越searchmanagerinstance並調用觸發搜索:的Android SearchManager的triggersearch給空指針異常
07-17 12:17:04.650: E/AndroidRuntime(1265): java.lang.IllegalStateException: Could not execute method of the activity
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.view.View$1.onClick(View.java:3591)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.view.View.performClick(View.java:4084)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.view.View$PerformClick.run(View.java:16966)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.os.Handler.handleCallback(Handler.java:615)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.os.Looper.loop(Looper.java:137)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-17 12:17:04.650: E/AndroidRuntime(1265): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 12:17:04.650: E/AndroidRuntime(1265): at java.lang.reflect.Method.invoke(Method.java:511)
07-17 12:17:04.650: E/AndroidRuntime(1265): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-17 12:17:04.650: E/AndroidRuntime(1265): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-17 12:17:04.650: E/AndroidRuntime(1265): at dalvik.system.NativeStart.main(Native Method)
07-17 12:17:04.650: E/AndroidRuntime(1265): Caused by: java.lang.reflect.InvocationTargetException
07-17 12:17:04.650: E/AndroidRuntime(1265): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 12:17:04.650: E/AndroidRuntime(1265): at java.lang.reflect.Method.invoke(Method.java:511)
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.view.View$1.onClick(View.java:3586)
07-17 12:17:04.650: E/AndroidRuntime(1265): ... 11 more
07-17 12:17:04.650: E/AndroidRuntime(1265): Caused by: java.lang.NullPointerException
07-17 12:17:04.650: E/AndroidRuntime(1265): at android.app.SearchManager.triggerSearch(SearchManager.java:635)
嘗試'組件名稱(getApplicationContext ().getPackageName(),MainActivity.class)' – Simon
使用SearchManager試一試s =(SearchManager)MainAcitivity.this.getSystemService(Context.SEARCH_SERVICE); – Nas
有沒有構造函數匹配,最接近會是這樣的: 新的ComponentName(getApplicationContext(),MainActivity.class) 仍然有NPE –