1. Are you ready for the Galaxy S20? Here is everything we know so far!

Getlong error in MatrixCursor while in suggestion search framework

Discussion in 'Android Development' started by theophany77, Jan 4, 2019.

  1. theophany77

    theophany77 Newbie
    Thread Starter

    Hi,

    On my Samsung S7 Edge, I have developed a ContentProvider for my suggestion search (my app is about songs and should return some song names after typing a few letters as a suggestion ; ex : “bri” should return “across the bridge”) but it fails like this under Android Studio

    --------- beginning of crash

    2018-12-21 11:35:06.953 31905-31905/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main

    Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 31905

    java.lang.NumberFormatException: For input string: "glo"
    at java.lang.Long.parseLong(Long.java:590)
    at java.lang.Long.parseLong(Long.java:632)
    at android.database.MatrixCursor.getLong(MatrixCursor.java:280)

    I have a very simple matrixcursor for the columns required by the search framework given there is only the mandatory " _id" column in it :

    1. private static String matrixCursorColumns = {"_id"};

    Here is the source code for some important lines and the query cursor




    Code (Text):
    1.  
    2. private static final int SEARCH_SUGGEST = 0;
    3. private static final int SEARCH_SUGGESTIONS = 1;
    4. private static final int SHORTCUT_REFRESH=1
    5.  
    6.  
    7. private static final String AUTHORITY=“songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider”;
    8.  
    9.  
    10.  
    11.  
    12. static final Uri CONTENT_URI=Uri.parse( “content://”+AUTHORITY);
    13. mUriMatcher = new UriMatcher( UriMatcher.NO_MATCH );
    14. mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    15. mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + “/*”, SEARCH_SUGGEST);
    16.  
    17.  
    18. public Cursor query(@NonNull Uri uri, [USER=1996173]@nullable[/USER] String projection,
    19. [USER=1996173]@nullable[/USER] String selection,
    20. [USER=1996173]@nullable[/USER] String selectionArgs,
    21. [USER=1996173]@nullable[/USER] String sortOrder) {
    22. String query = uri.getLastPathSegment().toLowerCase();
    23.  
    24.  
    25.    if (mUriMatcher.match(uri) == SEARCH_SUGGEST) {
    26.            Log.i("DEBUG_Sea_Cont_Prov", "query: if match");
    27.            //String query = uri.getLastPathSegment().toLowerCase();
    28.            return getSearchResultsCursor(query);
    29.    }
    30.    else {
    31.        Log.i("DEBUG_Sea_Cont_Prov", "query: else");
    32.    }
    33.  
    34.    return null;
    35. }
    36.  
    37. private MatrixCursor getSearchResultsCursor(String searchString){
    38.                searchResults.addRow( createRow1(searchString) );
    39.            }
    40.        }
    41.    }
    42.    Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avant return: mRow:"+searchResults.toString());
    43.    //for (int i = 0; i < searchResults.getCount(); i++) {
    44.    //    Log.i("DEBUG_Sea_Cont_Prov", "searchResults :"+searchResults.getString( i ));
    45.    //}
    46.  
    47.    return searchResults;    }
    48.  
    49. private Object[] createRow1(String query)
    50. {
    51.    Log.i("DEBUG_Sea_Cont_Prov", "Entree dans createRow1 avec query:"+query);
    52.    //return columnValuesOfQuery(query,"query");
    53.    return columnValuesOfQuery(query);
    54. }
    55.  
    56. private Object[] columnValuesOfQuery(String query)
    57. {
    58.    Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
    59.    return new String[]
    60.            {
    61.                    query
    62.            };
    63. }
    64.  

    Even if I add another column (SUGGEST_COLUMN_TEXT_1), it fails the same way.
    Do you have an idea ?
    Why is the Getlong used for in the MatrixCursor ?

    Thanks in advance.

    Jean-michel, Nemours, France

    PS : I have already posted that same question on "https://forums.bignerdranch.com/t/g...or-while-in-suggestion-search-framework/15653" but with no answer so far.

     


    #1 theophany77, Jan 4, 2019
    Last edited by a moderator: Jan 4, 2019
  2. Best Answer:
    Post #13 by Deleted User, Jan 5, 2019 (3 points)
  3. Deleted User

    Deleted User Guest

    What's at line 280 in MatrixCursor.java? Because that's where your problem is.
     
  4. theophany77

    theophany77 Newbie
    Thread Starter

    Hi,
    Thx for answering so quickly.
    Could you please write the line ? I am not with my laptop and I do not see the line number ?
    Thx.
    Jean-michel
     
  5. theophany77

    theophany77 Newbie
    Thread Starter

    Sorry ... I got it ... I will then post the line asap.
    Thx.
     
  6. Deleted User

    Deleted User Guest

    Oh sorry, MatrixCursor is a framework class, not your code.
    But we need to see the full stack trace, not just those 4 lines. It must show the call stack right back to your code.
    And we also need to see the relevant part of your code. Please use [/code][/code] tags to format it nicely.
     
  7. theophany77

    theophany77 Newbie
    Thread Starter

    Hi LV,
    Here is the full stack :

    /code

    2019-01-04 22:39:49.500 1575-1667/songs4heaven_p2.com.hfad.songs4heaven_p2 I/DEBUG_Sea_Cont_Prov: getSearchResultsCursor: for -> title:A l appel de la trompette
    2019-01-04 22:39:49.500 1575-1667/songs4heaven_p2.com.hfad.songs4heaven_p2 I/DEBUG_Sea_Cont_Prov: getSearchResultsCursor: avant return: mRow:android.database.MatrixCursor@232580
    2019-01-04 22:39:49.514 5453-5453/? I/SKBD: ajd [PF_KL][SIIC] getCursorCapsMode done 15
    2019-01-04 22:39:49.515 1575-1575/songs4heaven_p2.com.hfad.songs4heaven_p2 D/AndroidRuntime: Shutting down VM


    --------- beginning of crash
    2019-01-04 22:39:49.518 1575-1575/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 1575
    java.lang.NumberFormatException: For input string: "glo"
    at java.lang.Long.parseLong(Long.java:590)
    at java.lang.Long.parseLong(Long.java:632)
    at android.database.MatrixCursor.getLong(MatrixCursor.java:280)
    at android.database.CursorWrapper.getLong(CursorWrapper.java:127)
    at android.support.v4.widget.CursorAdapter.getItemId(CursorAdapter.java:230)
    at android.widget.AutoCompleteTextView.buildImeCompletions(AutoCompleteTextView.java:1254)
    at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1209)
    at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:1092)
    at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:1074)
    at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
    2019-01-04 22:39:49.525 4974-10375/? D/Debug: !@DumpState : SHIP
    2019-01-04 22:39:49.525 4974-10375/? D/Debug: !@DumpState : debug level:0x4f4c
    /code

    Sorry but I do not see the code tags or the appropriate icon.
    Thank you.
    Jean-michel
     
  8. Deleted User

    Deleted User Guest

    I'm afraid there isn't enough information here to solve the problem.
    First thing is, you need to understand what a stack trace is, and how it helps you to track down the causes of a crash. Do you know what an Exception is, and what it means when your code throws one?
    You can read this thread for some further information on diagnosing problems using stack traces, and debugging your code with breakpoints

    https://androidforums.com/threads/please-read-me-before-posting.987318/

    As it stands, you've not given enough information because we need to see:-

    1. The full stack trace, going right back to your code
    2. The piece of code which generated the exception

    If you don't provide this information, unfortunately nobody can help you.
     
    GameTheory likes this.
  9. GameTheory

    GameTheory Android Expert

    I'd like to reiterate what LV426 said earlier. When you post any code wrap it in code tags like in this image...

    [​IMG]
     
    Deleted User likes this.
  10. theophany77

    theophany77 Newbie
    Thread Starter

    Thank you all for your help.
    I feel very sorry for not given the required information.
    I do not practice java enough, as well as Android Studio, to know some important information you need.
    I am going to study the meaning of Exception and stack trace before sending anything new.
    Once again, than you and sorry for the inconvenience.
     
    GameTheory and Deleted User like this.
  11. Deleted User

    Deleted User Guest

    It's no inconvenience, and people will help, but you just need to give the right information.
    If you're new to app development, then you will really benefit from understanding certain basic concepts, which will improve your productivity tremendously. By all means ask questions, but there is a lot you can do to help yourself, and you'll get a great sense of achievement by increasing your understanding, and being able to solve problems. It's not hard, just takes a bit of time and patience to acquire the knowledge.
     
    GameTheory likes this.
  12. theophany77

    theophany77 Newbie
    Thread Starter

    Thank you for your kindness and help.
    I have been learning Android native dev for about one year on my own through some books but this suggestion search error is a mystery to me. I have studied other projects on Github, bought a special book talking about the search framework but no way to understand it yet. I guess I do not possess the URI notions enough in and outside a MatrixCursor context.
    Thx once again.
     
  13. theophany77

    theophany77 Newbie
    Thread Starter

    Hi,
    Here is the stack trace :

    Code (Text):
    1.  
    2.     --------- beginning of crash
    3. 2019-01-05 19:47:32.913 13680-13680/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main
    4.     Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 13680
    5.     java.lang.NumberFormatException: For input string: "glo"
    6.         at java.lang.Long.parseLong(Long.java:590)
    7.         at java.lang.Long.parseLong(Long.java:632)
    8.         at android.database.MatrixCursor.getLong(MatrixCursor.java:280)
    9.         at android.database.CursorWrapper.getLong(CursorWrapper.java:127)
    10.         at android.support.v4.widget.CursorAdapter.getItemId(CursorAdapter.java:230)
    11.         at android.widget.AutoCompleteTextView.buildImeCompletions(AutoCompleteTextView.java:1254)
    12.         at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1209)
    13.         at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:1092)
    14.         at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:1074)
    15.         at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
    16.         at android.os.Handler.dispatchMessage(Handler.java:105)
    17.         at android.os.Looper.loop(Looper.java:164)
    18.         at android.app.ActivityThread.main(ActivityThread.java:6944)
    19.         at java.lang.reflect.Method.invoke(Native Method)
    20.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    21.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
    22.  
    23.  
    It happens immediately after typing three letters ("glo" in the present case) in any suggestion search.
    In the searchable.xml file, there is the following attribute :

    Code (Text):
    1.  
    2. android:searchSuggestThreshold="3"
    3.  
    It surely happens in the ContentProvider when the search framework tries to do something with the letters typed.
    The exception (java.lang.NumberFormatException: For input string: "glo") seems to come from the MatrixCursor waiting for a Long object and receiving a string ("glo") object. Am i wrong ?

    Here is the code of the whole ContentProvider, event though I do not see the getLong mentioned in the stack trace :

    Code (Text):
    1.  
    2. package songs4heaven_p2.com.hfad.songs4heaven_p2;
    3.  
    4.  
    5. import android.app.SearchManager;
    6. import android.content.ContentProvider;
    7. import android.content.ContentValues;
    8. import android.content.UriMatcher;
    9. import android.database.Cursor;
    10. import android.database.MatrixCursor;
    11. import android.net.Uri;
    12. import android.support.annotation.NonNull;
    13. import android.support.annotation.Nullable;
    14. import android.util.Log;
    15.  
    16. import java.util.List;
    17.  
    18. public class SearchContentProvider extends ContentProvider{
    19.  
    20.     public List<Song> songs = null;
    21.  
    22.     //content mime types
    23.     /*
    24.     private static final String BASE_DATA_NAME="songs";
    25.     // Dans le manifeste :
    26.     //      <data android:mimeType="vnd.android.cursor.item/vnd.songs4heaven.search.songs" />
    27.     public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    28.     public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    29.     private static final String AUTHORITY="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider";
    30.  
    31.     //common URIs
    32.      static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY+"/"+BASE_DATA_NAME );
    33.     private static final Uri SEARCH_SUGGEST_URI=Uri.parse( "content://"+AUTHORITY+"/"
    34.             +BASE_DATA_NAME + "/"
    35.             + SearchManager.SUGGEST_URI_PATH_QUERY );
    36.             //+1);
    37.  
    38. */
    39.  
    40.     // Uri matcher to decode incoming URIs.
    41.     private final UriMatcher mUriMatcher;
    42.  
    43.     private static final int SONGS = 1; // The incoming URI matches the main table URI pattern
    44.     private static final int SONGS_ID = 2; // The incoming URI matches the main table row ID URI pattern
    45.     private static final int SEARCH_SUGGEST = 0;
    46.  
    47.     private static final int SEARCH_SUGGESTIONS = 1;
    48.     private static final int SHORTCUT_REFRESH=1;
    49.     //private static final String BASE_DATA_NAME="songs";
    50.     //public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    51.     //public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    52.     private static final String AUTHORITY="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider";
    53.  
    54.     //static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY+"/"+BASE_DATA_NAME );
    55.     static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY);
    56.     // sur modèle   http://www.zoftino.com/android-search-dialog-with-search-suggestions-example
    57.     //private static final String SONGS = "songs/"+ SearchManager.SUGGEST_URI_PATH_QUERY+"/*";
    58.  
    59.     //public static final Uri SEARCH_SUGGEST_URI = Uri.parse("content://" + AUTHORITY + "/"
    60.     //        + BASE_DATA_NAME + "/"
    61.     //        + SearchManager.SUGGEST_URI_PATH_QUERY);
    62.  
    63.     public SearchContentProvider() {
    64.  
    65.             // Dans EmployeeDirectory
    66.             // to get suggestions...
    67.             //  mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    68.             //  mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
    69.  
    70.             mUriMatcher = new UriMatcher( UriMatcher.NO_MATCH );
    71.  
    72.             // Les 2 lignes suivantes font échouer le programme
    73.             //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,SEARCH_SUGGESTIONS);
    74.             //mUriMatcher.addURI( AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY+"/*",SEARCH_SUGGESTIONS);
    75.  
    76.             // to get suggestions...
    77.             mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    78.             mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
    79.             //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, SHORTCUT_REFRESH);
    80.             //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", SHORTCUT_REFRESH);
    81.             //mUriMatcher.addURI( AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGESTIONS );
    82.             Log.i("DEBUG_Sea_Cont_Prov", "mUriMatcher:"+mUriMatcher.toString());
    83.             // Perte des suggestions
    84.             //uriMatcher.addURI(AUTHORITY, "/*",SEARCH_SUGGESTIONS);
    85.             //uriMatcher.addURI( AUTHORITY,
    86.             //        SONGS, SEARCH_SUGGESTIONS );
    87.     }
    88.  
    89.  
    90.  
    91.     //private static final String SONGS="songs/"+SearchManager.SUGGEST_URI_PATH_QUERY+"/*";
    92.  
    93.     // Allocate the UriMatcher object, recognize search requests.
    94.     // rappels :
    95.     //      android:searchSuggestAuthority="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider"
    96.     //      android:searchSuggestIntentData="content://songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider/songs"
    97.  
    98.     /* private static final UriMatcher uriMatcher;
    99.     static {
    100.         uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    101.         //uriMatcher.addURI(AUTHORITY, SONGS, SEARCH_SUGGESTIONS);
    102.         ////uriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,SEARCH_SUGGESTIONS);
    103.         uriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY+"/*",SEARCH_SUGGESTIONS);
    104.         */
    105.         // KO : uriMatcher.addURI(AUTHORITY,"/*",SEARCH_SUGGESTIONS);
    106.         //uriMatcher.addURI(AUTHORITY,SearchManager.SUGGEST_URI_PATH_QUERY + "/*",SEARCH_SUGGESTIONS);
    107.         //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
    108.                 //SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGESTIONS);
    109.         //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
    110.                 //SearchManager.SUGGEST_URI_PATH_SHORTCUT, SEARCH_SUGGESTIONS);
    111.         //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
    112.                 //SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", SEARCH_SUGGESTIONS);
    113.     /////}
    114.  
    115.     public List<Song> mSongs = null;
    116.  
    117.     private static String[] matrixCursorColumns = {"_id",
    118.             SearchManager.SUGGEST_COLUMN_TEXT_1,
    119.             SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    120.  
    121.     @Override
    122.     public boolean onCreate() {
    123.         Log.i("DEBUG_Sea_Cont_Prov", "onCreate: entrée");
    124.         return true;
    125.     }
    126.  
    127.     @Nullable
    128.     @Override
    129.     // query de EmployeeDirectory
    130.     //public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    131.  
    132.     public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
    133.                         @Nullable String selection,
    134.                         @Nullable String[] selectionArgs,
    135.                         @Nullable String sortOrder) {
    136.         String query = uri.getLastPathSegment().toLowerCase();
    137.  
    138.         // ne marche pas
    139.         //String query = selectionArgs[0];
    140.  
    141.         Log.i("DEBUG_Sea_Cont_Prov", "query: query="+query);
    142.         Log.i("DEBUG_Sea_Cont_Prov", "query: getPath="+uri.getPath());
    143.         Log.i("DEBUG_Sea_Cont_Prov", "query: getQuery="+uri.getQuery());
    144.         Log.i("DEBUG_Sea_Cont_Prov", "query: getAuthority="+uri.getAuthority());
    145.  
    146.         if (mUriMatcher.match(uri) == SEARCH_SUGGEST) {
    147.                 Log.i("DEBUG_Sea_Cont_Prov", "query: if match");
    148.                 //String query = uri.getLastPathSegment().toLowerCase();
    149.                 return getSearchResultsCursor(query);
    150.         }
    151.         else {
    152.             Log.i("DEBUG_Sea_Cont_Prov", "query: else");
    153.         }
    154.  
    155.         return null;
    156.     }
    157.  
    158.     /*  @Nullable
    159.     @Override
    160.     public String getType(Uri uri) {
    161.         return null;
    162.     }   */
    163.  
    164.  
    165.     @Nullable
    166.     @Override
    167.     public String getType(Uri uri) {
    168.         switch (mUriMatcher.match(uri)) {
    169.             case SEARCH_SUGGEST:
    170.                 return SearchManager.SUGGEST_MIME_TYPE;
    171.             case SHORTCUT_REFRESH:
    172.                 return SearchManager.SHORTCUT_MIME_TYPE;
    173.             default:
    174.                 throw new IllegalArgumentException("DEBUG_Sear_Cont_Prov:getType:IllegalArgExc:Unknown URI");
    175.         }
    176.  
    177.        // return null;
    178.     }
    179.  
    180.     @Nullable
    181.     @Override
    182.     public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
    183.         Log.i("DEBUG_Sea_Cont_Prov", "insert");
    184.         return null;
    185.     }
    186.  
    187.     @Override
    188.     public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
    189.         return 0;
    190.     }
    191.  
    192.     @Override
    193.     public int update(@NonNull Uri uri, @Nullable ContentValues contentValues,
    194.                       @Nullable String s, @Nullable String[] strings) {
    195.         return 0;
    196.     }
    197.  
    198.     private MatrixCursor getSearchResultsCursor(String searchString){
    199.         Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: searchString1 :"+searchString);
    200.  
    201.         MatrixCursor searchResults =  new MatrixCursor(matrixCursorColumns);
    202.         //Object[] mRow = new Object[2];
    203.  
    204.         int counterId = 0;
    205.         if(searchString != null){
    206.             searchString = searchString.toLowerCase();
    207.  
    208.             //String v_titre = "";
    209.  
    210.             //for (int i = 0; i < songs.size(); i++) {
    211.             //v_titre = songs.get( i )._title;
    212.             //}
    213.  
    214.             Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: searchString2 : "+searchString);
    215.  
    216.             mSongs = SingleLoadXml.getSongs( getContext());
    217.             for (int i = 0; i < mSongs.size(); i++) {
    218.                 int id = mSongs.get( i )._ID;
    219.                 String title = mSongs.get( i )._title;
    220.                 String words = mSongs.get( i )._words;
    221.                 Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: for -> title:"+title);
    222.  
    223.                 if (title.toLowerCase().contains( searchString )) {
    224.                     //mRow[0] = "" + counterId++;
    225.                     //mRow[0] = searchString;
    226.                     //mRow[1] = "query";
    227.                     //mRow[2] = "" + counterId++;
    228.                     //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avec mRow:"
    229.                     //        +mRow[0].toString()+"/"+mRow[1].toString());
    230.  
    231.                             //+searchResults.getColumnName( 2 ) );
    232.                     //searchResults.addRow( mRow );
    233.  
    234.                     //Echoue à la compilation ce 20181218
    235.                     Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avec searchString:"+searchString);
    236.                     searchResults.addRow( createRow1(searchString) );
    237.  
    238.                     // android.database.CursorIndexOutOfBoundsException: Before first row.
    239.                     //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: getlong(0) : "+searchResults.getLong( 0 ));
    240.                     //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: getlong(1) : "+searchResults.getLong( 1 ));
    241.  
    242.                     //mRow[0] = searchString;
    243.                     //mRow[1] = "query";
    244.                     //searchResults.addRow( mRow ) ;
    245.  
    246.                     Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: apres addRow:"+searchResults.toString());
    247.                 }
    248.             }
    249.         }
    250.         Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avant return: mRow:"+searchResults.toString());
    251.         //for (int i = 0; i < searchResults.getCount(); i++) {
    252.         //    Log.i("DEBUG_Sea_Cont_Prov", "searchResults :"+searchResults.getString( i ));
    253.         //}
    254.  
    255.         return searchResults;    }
    256.  
    257.     private Object[] createRow1(String query)
    258.     {
    259.         Log.i("DEBUG_Sea_Cont_Prov", "Entree dans createRow1 avec query:"+query);
    260.         return columnValuesOfQuery(query,"query","android.intent.action.VIEW");
    261.         //return columnValuesOfQuery(query);
    262.     }
    263.  
    264.     private Object[] columnValuesOfQuery(String query, String text1, String intentAction)
    265.     {
    266.         Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
    267.         return new String[]
    268.                 {
    269.                         query,
    270.                         text1,
    271.                         intentAction
    272.                 };
    273.     }
    274.  
    275. }
    276.  
    Am I building my MatrixCursor incorrectly ?
    Code (Text):
    1.  
    2. private static String[] matrixCursorColumns = {"_id",
    3.         SearchManager.SUGGEST_COLUMN_TEXT_1,
    4.         SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    5.  
    6.  
    columnValuesOfQuery seems to returns the right number of arguments required by the cursor :

    Code (Text):
    1.  
    2. private Object[] columnValuesOfQuery(String query, String text1, String intentAction)
    3. {
    4.     Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
    5.     return new String[]
    6.             {
    7.                     query,
    8.                     text1,
    9.                     intentAction
    10.             };
    11. }
    12.  
    Did I send the correct things now for you ?

    Thank you.
    Jean-michel
     
  14. Deleted User

    Deleted User Guest

    Code (Text):
    1.  
    2. private static String[] matrixCursorColumns = {"_id",
    3.             SearchManager.SUGGEST_COLUMN_TEXT_1,
    4.             SearchManager.SUGGEST_COLUMN_INTENT_DATA };
    5.  
    Right, this is something I've not used before myself, but I'm guessing that this array specifies the columns in your database table, that the matcher will use to find matching records.
    I'm also presuming that column "_id" is of type LONG, so that could explain the exception when you try to use a value of "glo" to search. Obviously "glo" isn't a number, and can't be converted to a number, hence the exception.
    Just guessing really. You could try either taking "_id" out of the array, or typing in an actual number into your search box.
     
    GameTheory likes this.
  15. theophany77

    theophany77 Newbie
    Thread Starter

    Good guess !
    When updating my xml file and adding "777" in a song title, there is a match when searching for "777" and no exception where it used to be one.
    There is then another exception but I am going to study the good guess given the suggestion displayed is black (no title at all).
    Thank you for your help.
    Jean-michel
     
  16. theophany77

    theophany77 Newbie
    Thread Starter

    My problem is solved.
    Someone helped me and showed me that the matrixCursor I was sending back to the query method contained a first row of String type instead of the integer type requested by the search framework.
    Thank you.
     
  17. theophany77

    theophany77 Newbie
    Thread Starter

    You were right LV426.
    Thanks a lot.
     
  18. theophany77

    theophany77 Newbie
    Thread Starter

    Hi,

    I encounter a new problem in my suggestion search.
    Even though the suggestion appears, is clickable and starts normally the search activity,
    I cannot start the details activity mentioned in my manifest file:

    Code (Text):
    1.  
    2.         <activity
    3.             android:name=".DetailsActivity"
    4.             android:label="@string/song_details" >
    5.             <intent-filter tools:ignore="AppLinkUrlError">
    6.                 <action android:name="android.intent.action.VIEW" />
    7.                 <category android:name="android.intent.category.DEFAULT" />
    8.          </intent-filter>
    9.         </activity>
    10.  
    It fails this way :

    Code (Text):
    1.    
    2. 2019-01-22 10:57:04.216 20202-20202/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main
    3.     Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 20202
    4.     java.lang.RuntimeException: Unable to start activity ComponentInfo{songs4heaven_p2.com.hfad.songs4heaven_p2/songs4heaven_p2.com.hfad.songs4heaven_p2.SearchAndroidActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://songs4heaven_p2.com.hfad.songs4heaven_p2.DetailsActivity (has extras) }
    5.         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
    6.         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    7.         at android.app.ActivityThread.-wrap11(Unknown Source:0)
    8.         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    9.         at android.os.Handler.dispatchMessage(Handler.java:105)
    10.         at android.os.Looper.loop(Looper.java:164)
    11.         at android.app.ActivityThread.main(ActivityThread.java:6944)
    12.         at java.lang.reflect.Method.invoke(Native Method)
    13.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    14.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
    15.      Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://songs4heaven_p2.com.hfad.songs4heaven_p2.DetailsActivity (has extras) }
    16.         at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1968)
    17.         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1622)
    18.         at android.app.Activity.startActivityForResult(Activity.java:4564)
    19.         at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
    20.         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
    21.         at android.app.Activity.startActivityForResult(Activity.java:4522)
    22.         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
    23.         at android.app.Activity.startActivity(Activity.java:4883)
    24.         at android.app.Activity.startActivity(Activity.java:4851)
    25.         at songs4heaven_p2.com.hfad.songs4heaven_p2.SearchAndroidActivity.handleIntent(SearchAndroidActivity.java:164)
    26.         at songs4heaven_p2.com.hfad.songs4heaven_p2.SearchAndroidActivity.onCreate(SearchAndroidActivity.java:40)
    27.         at android.app.Activity.performCreate(Activity.java:7174)
    28.         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    29.         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
    30.         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    31.         at android.app.ActivityThread.-wrap11(Unknown Source:0)
    32.         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    33.         at android.os.Handler.dispatchMessage(Handler.java:105)
    34.         at android.os.Looper.loop(Looper.java:164)
    35.         at android.app.ActivityThread.main(ActivityThread.java:6944)
    36.         at java.lang.reflect.Method.invoke(Native Method)
    37.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    38.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
    39.  
    I really do not understand it given the intent mentioned in the error stack is android.intent.action.VIEW, just like the manifest is expecting.

    The only way for me to start it normally is to use an explicit intent in the Provider class :

    Code (Text):
    1.    
    2. detailsIntent = new Intent(this, DetailsActivity.class);
    3. startActivity(detailsIntent);
    4.  
    If I try to use the searchSuggestIntentData parameter in the searchable.xml file, it fails :

    Code (Text):
    1.    
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <searchable xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:hint="@string/search_hint"
    5.     android:label="@string/app_name"
    6.     android:searchSuggestAuthority="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider"
    7.     android:searchSuggestIntentAction="android.intent.action.VIEW"
    8.     android:searchSuggestIntentData="content://songs4heaven_p2.com.hfad.songs4heaven_p2.DetailsActivity"
    9.     android:searchSuggestThreshold="5">
    10. </searchable>
    11.  
    Even if I try to call the DetailsActivity this way, it fails :

    Code (Text):
    1.    
    2. Uri details = intent.getData();
    3. Intent detailsIntent = new Intent(Intent.ACTION_VIEW, details  );
    4.  
    Last but not least, if I do not mention any startActivity command in the SearchActivity class, a chooser pops up
    with many activities including the song_details one which is the android:label in my manifest for the DetailsActivity.

    My project is available at the following url in Github :
    https://github.com/theophany77/Songs4Heaven_p2

    Thank you in advance for your help.

    Jean-michel
     
Loading...
Similar Threads - Getlong error MatrixCursor
  1. Bahria Town Rawalpindi
    Replies:
    13
    Views:
    220
  2. SteveD_Rdg
    Replies:
    0
    Views:
    258
  3. Christopher Clayton
    Replies:
    0
    Views:
    121
  4. Waldek
    Replies:
    0
    Views:
    166
  5. Danz47
    Replies:
    0
    Views:
    656
  6. HeadScratcher
    Replies:
    6
    Views:
    940
  7. CharlesLewis
    Replies:
    11
    Views:
    657
  8. Doulos Adonai
    Replies:
    1
    Views:
    388
  9. Charles Lee
    Replies:
    5
    Views:
    504
  10. Amol More
    Replies:
    4
    Views:
    230

Share This Page

Loading...