我的應用程序使用應用內搜索,動態建立每個請求的搜索建議,將它們放入MatrixCursor
並返回要顯示的建議。在這裏搜索建議信息:
http://developer.android.com/guide/topics/search/adding-custom-suggestions.html搜索建議失敗2.2
這個工作在2.1 UPDATE1完全正常,但是當我裝好了一個2.2的手機上,我得到一個致命的錯誤,當我嘗試搜索。下面是相關的日誌:
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): error changing cursor and caching columns
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): java.lang.NumberFormatException: My String Message
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at java.lang.Long.parse(Long.java:364)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at java.lang.Long.parseLong(Long.java:354)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at java.lang.Long.parseLong(Long.java:320)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.database.MatrixCursor.getLong(MatrixCursor.java:255)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.database.CursorWrapper.getLong(CursorWrapper.java:127)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.CursorAdapter.getItemId(CursorAdapter.java:156)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.AutoCompleteTextView.buildDropDown(AutoCompleteTextView.java:1248)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1137)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:1019)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:1002)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.app.SearchDialog.onDataSetChanged(SearchDialog.java:612)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.app.SuggestionsAdapter.notifyDataSetChanged(SuggestionsAdapter.java:193)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.CursorAdapter.changeCursor(CursorAdapter.java:260)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.app.SuggestionsAdapter.changeCursor(SuggestionsAdapter.java:238)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.CursorFilter.publishResults(CursorFilter.java:67)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.os.Looper.loop(Looper.java:123)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at java.lang.reflect.Method.invoke(Method.java:521)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-22 12:13:05.935: ERROR/SuggestionsAdapter(1028): at dalvik.system.NativeStart.main(Native Method)
07-22 12:13:05.935: DEBUG/AndroidRuntime(1028): Shutting down VM
07-22 12:13:05.935: WARN/dalvikvm(1028): threadid=1: thread exiting with uncaught exception (group=0x4001d7f0)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): FATAL EXCEPTION: main
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): java.lang.NumberFormatException: My String Message
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at java.lang.Long.parse(Long.java:364)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at java.lang.Long.parseLong(Long.java:354)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at java.lang.Long.parseLong(Long.java:320)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.database.MatrixCursor.getLong(MatrixCursor.java:255)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.database.CursorWrapper.getLong(CursorWrapper.java:127)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.CursorAdapter.getItemId(CursorAdapter.java:156)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.AutoCompleteTextView.buildDropDown(AutoCompleteTextView.java:1248)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1137)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:1019)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:1002)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.os.Looper.loop(Looper.java:123)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at java.lang.reflect.Method.invoke(Method.java:521)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-22 12:13:05.945: ERROR/AndroidRuntime(1028): at dalvik.system.NativeStart.main(Native Method)
其中「我的字符串信息」是第一個(在這種情況下,僅)行的SUGGEST_COLUMN_TEXT_1字段的值將被返回作爲光標的建議。堆棧跟蹤根本不觸碰我的代碼,並且在調試器中跟蹤它,顯示在我的搜索建議內容提供程序中返回建議光標後的一段時間內發生錯誤。
爲什麼他們的適配器突然嘗試將字符串解釋爲長整型?有人遇到過這種情況麼?
謝謝!
這是問題所在。當我得到的代碼有一個字符串(與text1相同的字符串)進入ID,但它並不重要,並在2.1它工作,所以我剛剛離開它。顯然在2.2上,它被強制執行爲一個Long。 – 2010-07-23 21:01:23
我也面臨同樣的問題在android 2.2,請提供一些更多的信息來解決這個問題。請 – 2010-10-22 15:30:38