• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Getlong error in MatrixCursor while in suggestion search framework

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:
private static final int SEARCH_SUGGEST = 0;
private static final int SEARCH_SUGGESTIONS = 1;
private static final int SHORTCUT_REFRESH=1
…

 
private static final String AUTHORITY=“songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider”;

 
…

 
static final Uri CONTENT_URI=Uri.parse( “content://”+AUTHORITY);
mUriMatcher = new UriMatcher( UriMatcher.NO_MATCH );
mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + “/*”, SEARCH_SUGGEST);
…

 
public Cursor query(@NonNull Uri uri, [USER=1996173]@nullable[/USER] String projection,
[USER=1996173]@nullable[/USER] String selection,
[USER=1996173]@nullable[/USER] String selectionArgs,
[USER=1996173]@nullable[/USER] String sortOrder) {
String query = uri.getLastPathSegment().toLowerCase();

 
   if (mUriMatcher.match(uri) == SEARCH_SUGGEST) {
           Log.i("DEBUG_Sea_Cont_Prov", "query: if match");
           //String query = uri.getLastPathSegment().toLowerCase();
           return getSearchResultsCursor(query);
   }
   else {
       Log.i("DEBUG_Sea_Cont_Prov", "query: else");
   }

   return null;
}

private MatrixCursor getSearchResultsCursor(String searchString){
               searchResults.addRow( createRow1(searchString) );
           }
       }
   }
   Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avant return: mRow:"+searchResults.toString());
   //for (int i = 0; i < searchResults.getCount(); i++) {
   //    Log.i("DEBUG_Sea_Cont_Prov", "searchResults :"+searchResults.getString( i ));
   //}

   return searchResults;    }

private Object[] createRow1(String query)
{
   Log.i("DEBUG_Sea_Cont_Prov", "Entree dans createRow1 avec query:"+query);
   //return columnValuesOfQuery(query,"query");
   return columnValuesOfQuery(query);
}

private Object[] columnValuesOfQuery(String query)
{
   Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
   return new String[]
           {
                   query
           };
}

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.
 
Last edited by a moderator:
What's at line 280 in MatrixCursor.java? Because that's where your problem is.
 
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.
 
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
 
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.
 
I'd like to reiterate what LV426 said earlier. When you post any code wrap it in code tags like in this image...

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

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.
 
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.
 
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.

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.
 
Hi,
Here is the stack trace :

Code:
    --------- beginning of crash
2019-01-05 19:47:32.913 13680-13680/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 13680
    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)

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:
android:searchSuggestThreshold="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:
package songs4heaven_p2.com.hfad.songs4heaven_p2;


import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.List;

public class SearchContentProvider extends ContentProvider{

    public List<Song> songs = null;

    //content mime types
    /*
    private static final String BASE_DATA_NAME="songs";
    // Dans le manifeste :
    //      <data android:mimeType="vnd.android.cursor.item/vnd.songs4heaven.search.songs" />
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    private static final String AUTHORITY="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider";

    //common URIs
     static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY+"/"+BASE_DATA_NAME );
    private static final Uri SEARCH_SUGGEST_URI=Uri.parse( "content://"+AUTHORITY+"/"
            +BASE_DATA_NAME + "/"
            + SearchManager.SUGGEST_URI_PATH_QUERY );
            //+1);

*/

    // Uri matcher to decode incoming URIs.
    private final UriMatcher mUriMatcher;

    private static final int SONGS = 1; // The incoming URI matches the main table URI pattern
    private static final int SONGS_ID = 2; // The incoming URI matches the main table row ID URI pattern
    private static final int SEARCH_SUGGEST = 0;

    private static final int SEARCH_SUGGESTIONS = 1;
    private static final int SHORTCUT_REFRESH=1;
    //private static final String BASE_DATA_NAME="songs";
    //public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    //public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.songs4heaven.search." + BASE_DATA_NAME;
    private static final String AUTHORITY="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider";

    //static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY+"/"+BASE_DATA_NAME );
    static final Uri CONTENT_URI=Uri.parse( "content://"+AUTHORITY);
    // sur modèle   http://www.zoftino.com/android-search-dialog-with-search-suggestions-example
    //private static final String SONGS = "songs/"+ SearchManager.SUGGEST_URI_PATH_QUERY+"/*";

    //public static final Uri SEARCH_SUGGEST_URI = Uri.parse("content://" + AUTHORITY + "/"
    //        + BASE_DATA_NAME + "/"
    //        + SearchManager.SUGGEST_URI_PATH_QUERY);

    public SearchContentProvider() {

            // Dans EmployeeDirectory
            // to get suggestions...
            //  mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
            //  mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);

            mUriMatcher = new UriMatcher( UriMatcher.NO_MATCH );

            // Les 2 lignes suivantes font échouer le programme
            //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,SEARCH_SUGGESTIONS);
            //mUriMatcher.addURI( AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY+"/*",SEARCH_SUGGESTIONS);

            // to get suggestions...
            mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
            mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
            //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, SHORTCUT_REFRESH);
            //mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", SHORTCUT_REFRESH);
            //mUriMatcher.addURI( AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGESTIONS );
            Log.i("DEBUG_Sea_Cont_Prov", "mUriMatcher:"+mUriMatcher.toString());
            // Perte des suggestions
            //uriMatcher.addURI(AUTHORITY, "/*",SEARCH_SUGGESTIONS);
            //uriMatcher.addURI( AUTHORITY,
            //        SONGS, SEARCH_SUGGESTIONS );
    }



    //private static final String SONGS="songs/"+SearchManager.SUGGEST_URI_PATH_QUERY+"/*";

    // Allocate the UriMatcher object, recognize search requests.
    // rappels :
    //      android:searchSuggestAuthority="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider"
    //      android:searchSuggestIntentData="content://songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider/songs"

    /* private static final UriMatcher uriMatcher;
    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        //uriMatcher.addURI(AUTHORITY, SONGS, SEARCH_SUGGESTIONS);
        ////uriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,SEARCH_SUGGESTIONS);
        uriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY+"/*",SEARCH_SUGGESTIONS);
        */
        // KO : uriMatcher.addURI(AUTHORITY,"/*",SEARCH_SUGGESTIONS);
        //uriMatcher.addURI(AUTHORITY,SearchManager.SUGGEST_URI_PATH_QUERY + "/*",SEARCH_SUGGESTIONS);
        //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
                //SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGESTIONS);
        //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
                //SearchManager.SUGGEST_URI_PATH_SHORTCUT, SEARCH_SUGGESTIONS);
        //uriMatcher.addURI("songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider",
                //SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", SEARCH_SUGGESTIONS);
    /////}

    public List<Song> mSongs = null;

    private static String[] matrixCursorColumns = {"_id",
            SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_INTENT_DATA };

    @Override
    public boolean onCreate() {
        Log.i("DEBUG_Sea_Cont_Prov", "onCreate: entrée");
        return true;
    }

    @Nullable
    @Override
    // query de EmployeeDirectory
    //public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
                        @Nullable String selection,
                        @Nullable String[] selectionArgs,
                        @Nullable String sortOrder) {
        String query = uri.getLastPathSegment().toLowerCase();

        // ne marche pas
        //String query = selectionArgs[0];

        Log.i("DEBUG_Sea_Cont_Prov", "query: query="+query);
        Log.i("DEBUG_Sea_Cont_Prov", "query: getPath="+uri.getPath());
        Log.i("DEBUG_Sea_Cont_Prov", "query: getQuery="+uri.getQuery());
        Log.i("DEBUG_Sea_Cont_Prov", "query: getAuthority="+uri.getAuthority());

        if (mUriMatcher.match(uri) == SEARCH_SUGGEST) {
                Log.i("DEBUG_Sea_Cont_Prov", "query: if match");
                //String query = uri.getLastPathSegment().toLowerCase();
                return getSearchResultsCursor(query);
        }
        else {
            Log.i("DEBUG_Sea_Cont_Prov", "query: else");
        }

        return null;
    }

    /*  @Nullable
    @Override
    public String getType(Uri uri) {
        return null;
    }   */


    @Nullable
    @Override
    public String getType(Uri uri) {
        switch (mUriMatcher.match(uri)) {
            case SEARCH_SUGGEST:
                return SearchManager.SUGGEST_MIME_TYPE;
            case SHORTCUT_REFRESH:
                return SearchManager.SHORTCUT_MIME_TYPE;
            default:
                throw new IllegalArgumentException("DEBUG_Sear_Cont_Prov:getType:IllegalArgExc:Unknown URI");
        }

       // return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
        Log.i("DEBUG_Sea_Cont_Prov", "insert");
        return null;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
        return 0;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues,
                      @Nullable String s, @Nullable String[] strings) {
        return 0;
    }

    private MatrixCursor getSearchResultsCursor(String searchString){
        Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: searchString1 :"+searchString);

        MatrixCursor searchResults =  new MatrixCursor(matrixCursorColumns);
        //Object[] mRow = new Object[2];

        int counterId = 0;
        if(searchString != null){
            searchString = searchString.toLowerCase();

            //String v_titre = "";

            //for (int i = 0; i < songs.size(); i++) {
            //v_titre = songs.get( i )._title;
            //}

            Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: searchString2 : "+searchString);

            mSongs = SingleLoadXml.getSongs( getContext());
            for (int i = 0; i < mSongs.size(); i++) {
                int id = mSongs.get( i )._ID;
                String title = mSongs.get( i )._title;
                String words = mSongs.get( i )._words;
                Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: for -> title:"+title);

                if (title.toLowerCase().contains( searchString )) {
                    //mRow[0] = "" + counterId++;
                    //mRow[0] = searchString;
                    //mRow[1] = "query";
                    //mRow[2] = "" + counterId++;
                    //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avec mRow:"
                    //        +mRow[0].toString()+"/"+mRow[1].toString());

                            //+searchResults.getColumnName( 2 ) );
                    //searchResults.addRow( mRow );

                    //Echoue à la compilation ce 20181218
                    Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avec searchString:"+searchString);
                    searchResults.addRow( createRow1(searchString) );

                    // android.database.CursorIndexOutOfBoundsException: Before first row.
                    //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: getlong(0) : "+searchResults.getLong( 0 ));
                    //Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: getlong(1) : "+searchResults.getLong( 1 ));

                    //mRow[0] = searchString;
                    //mRow[1] = "query";
                    //searchResults.addRow( mRow ) ;

                    Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: apres addRow:"+searchResults.toString());
                }
            }
        }
        Log.i("DEBUG_Sea_Cont_Prov", "getSearchResultsCursor: avant return: mRow:"+searchResults.toString());
        //for (int i = 0; i < searchResults.getCount(); i++) {
        //    Log.i("DEBUG_Sea_Cont_Prov", "searchResults :"+searchResults.getString( i ));
        //}

        return searchResults;    }

    private Object[] createRow1(String query)
    {
        Log.i("DEBUG_Sea_Cont_Prov", "Entree dans createRow1 avec query:"+query);
        return columnValuesOfQuery(query,"query","android.intent.action.VIEW");
        //return columnValuesOfQuery(query);
    }

    private Object[] columnValuesOfQuery(String query, String text1, String intentAction)
    {
        Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
        return new String[]
                {
                        query,
                        text1,
                        intentAction
                };
    }

}

Am I building my MatrixCursor incorrectly ?
Code:
private static String[] matrixCursorColumns = {"_id",
        SearchManager.SUGGEST_COLUMN_TEXT_1,
        SearchManager.SUGGEST_COLUMN_INTENT_DATA };

columnValuesOfQuery seems to returns the right number of arguments required by the cursor :

Code:
private Object[] columnValuesOfQuery(String query, String text1, String intentAction)
{
    Log.i("DEBUG_Sea_Cont_Prov", "Entree dans columnValuesOfQuery avec query:"+query);
    return new String[]
            {
                    query,
                    text1,
                    intentAction
            };
}

Did I send the correct things now for you ?

Thank you.
Jean-michel
 
Code:
private static String[] matrixCursorColumns = {"_id",
            SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_INTENT_DATA };

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.
 
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
 
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.
 
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:
        <activity
            android:name=".DetailsActivity"
            android:label="@string/song_details" >
            <intent-filter tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
        </activity>

It fails this way :

Code:
2019-01-22 10:57:04.216 20202-20202/songs4heaven_p2.com.hfad.songs4heaven_p2 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: songs4heaven_p2.com.hfad.songs4heaven_p2, PID: 20202
    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) }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        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)
     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) }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1968)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1622)
        at android.app.Activity.startActivityForResult(Activity.java:4564)
        at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
        at android.app.Activity.startActivityForResult(Activity.java:4522)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
        at android.app.Activity.startActivity(Activity.java:4883)
        at android.app.Activity.startActivity(Activity.java:4851)
        at songs4heaven_p2.com.hfad.songs4heaven_p2.SearchAndroidActivity.handleIntent(SearchAndroidActivity.java:164)
        at songs4heaven_p2.com.hfad.songs4heaven_p2.SearchAndroidActivity.onCreate(SearchAndroidActivity.java:40)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        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)
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:
detailsIntent = new Intent(this, DetailsActivity.class);
startActivity(detailsIntent);

If I try to use the searchSuggestIntentData parameter in the searchable.xml file, it fails :

Code:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_hint"
    android:label="@string/app_name"
    android:searchSuggestAuthority="songs4heaven_p2.com.hfad.songs4heaven_p2.SearchContentProvider"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:searchSuggestIntentData="content://songs4heaven_p2.com.hfad.songs4heaven_p2.DetailsActivity"
    android:searchSuggestThreshold="5">
</searchable>

Even if I try to call the DetailsActivity this way, it fails :

Code:
Uri details = intent.getData();
Intent detailsIntent = new Intent(Intent.ACTION_VIEW, details  );

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
 
Back
Top Bottom