修改InstantSearch Android示例会导致异常

时间:2017-09-21 13:44:20

标签: android algolia

我尝试从this link运行电子商务演示,我通过在自定义操作栏中设置搜索栏并在片段中调用hit_item UI进行修改。但是我得到了这个错误:

09-21 19:04:04.393 11716-11716/e_green_book.com.e_green_book E/EventBus: Could not dispatch event: class com.algolia.instantsearch.events.SearchEvent to subscribing class class com.algolia.instantsearch.helpers.SearchProgressController
java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.Menu.findItem(int)' on a null object reference
    at com.algolia.instantsearch.utils.SearchViewFacade.<init>(SearchViewFacade.java:40)
    at com.algolia.instantsearch.helpers.InstantSearch.updateProgressBar(InstantSearch.java:420)
    at com.algolia.instantsearch.helpers.InstantSearch.access$100(InstantSearch.java:47)
    at com.algolia.instantsearch.helpers.InstantSearch$1.onStart(InstantSearch.java:191)
    at com.algolia.instantsearch.helpers.SearchProgressController.onSearch(SearchProgressController.java:66)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
    at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:416)
    at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:397)
    at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:370)
    at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
    at com.algolia.instantsearch.helpers.Searcher.search(Searcher.java:172)
    at com.e_commerce.e_green_book.activity.MainActivity.onCreate(MainActivity.java:200)
    at android.app.Activity.performCreate(Activity.java:6736)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2744)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6195)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)

预计会出现此错误吗?我如何使用InstantSearch Android?

1 个答案:

答案 0 :(得分:3)

您应该能够立即使用InstantSearch Android。

如果您遇到的问题仅在修改代码时发生,您应该在您的问题中发布更改,以便让我们了解您的具体情况。

仅使用您共享的堆栈跟踪,您在menu传递的 registerSearchView(activity, menu, id) 引用似乎不包含使用给定 {{1 }}

id

这会引发searchView = (SearchView) menu.findItem(id).getActionView(); ,您应该检查NullPointerException调用的menuid参数,以确保菜单确实包含带有此registerSearchView的SearchView }。