tags:

views:

113

answers:

1

My application uses in-app search, dynamically builds search suggestions on each request, puts them in a MatrixCursor and returns the suggestions to be displayed. Info on search suggestions here:
http://developer.android.com/guide/topics/search/adding-custom-suggestions.html

This works perfectly fine in 2.1-update1, but when I loaded it on a 2.2 phone, I get a fatal error when I try to search. Here is the relevant logs:

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)

where "My String Message" is the value of the SUGGEST_COLUMN_TEXT_1 field of the first (in this case only) row to be returned as a suggestion in the cursor. The stack trace does not touch my code at all, and following it in a debugger shows the error occurs some time after I return the suggestions cursor in my search suggestion content provider.

Why is their adapter suddenly trying to interpret a String as a Long? Has anyone else encountered this?

Thanks!

+1  A: 

The code is failing when it's trying to access the ID column ("_id") which is required in any search suggestions cursor, and must be a Long.

Is it possible that you're not including that column, or, you're creating that column but writing your strings into it inadvertently?

See http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#SuggestionTable

Andy S.
This was the problem. When I got the code there was a string (same string as for text1) going into ID but it wasn't important and on 2.1 it worked so I just left it. Apparently on 2.2 it is fatally enforced as a Long.
B_
i too facing the same problem in android 2.2,please provide some more information to fix this issue.please
MGS