Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:04:46+00:00 2026-06-17T07:04:46+00:00

Secondly I’m really new in android and haven’t completely grasped the way it works

  • 0

Secondly I’m really new in android and haven’t completely grasped the way it works (which seems to be the case for the people who wrote most of the tutorials I could find online sadly so a good quick and dirty tutorial would also be great).
Moving on with the problem I’ll try to post only relevant code, if I skip something please let me know.

Manifest Entry:

<provider android:name="MyContentProvider" android:authorities="hua.it20910.android.provider"/>

Main activity call:

Cursor c = getContentProvider().query(MyContentProvider.getTableUri(1), null, null, null, null);

Content Provider:

private static SQLiteDatabase db;
private static final String database_name = "contactlist.db";
private static final int database_version = 1;
private static final String table1="Contacts";
private static final String[] table1_row={"_id","Surname","Name","Phone","Email","Address","Group"};
private static final String table2="Groups";
private static final String[] table2_row={"_id","Name"};

public static final String PROVIDER_NAME = "hua.it20910.android.provider";
public static final Uri CONTACTS_URI = Uri.parse("content://"+ PROVIDER_NAME + "/"+table1);
public static final Uri GROUPS_URI = Uri.parse("Content://"+PROVIDER_NAME + "/"+table2);

private static final int CONTACTS = 1;
private static final int CONTACT_ID = 2;
private static final int GROUPS = 3;
private static final int GROUP_ID = 4;

private static final UriMatcher myMatcher;
static {
    myMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    myMatcher.addURI(PROVIDER_NAME, table1, CONTACTS);
    myMatcher.addURI(PROVIDER_NAME, table1+"/#", CONTACT_ID);
    myMatcher.addURI(PROVIDER_NAME, table2, GROUPS);
    myMatcher.addURI(PROVIDER_NAME, table1+"/#", GROUP_ID);
}
private static final String table1Sql = "CREATE TABLE "
            + table1 + "(" 
            + table1_row[0] + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
            + table1_row[1] + " VARCHAR(25), "
            + table1_row[2] + " VARCHAR(25), " 
            + table1_row[3] + " INTEGER, " 
            + table1_row[4] + " VARCHAR(25), "
            + table1_row[5] + " VARCHAR(25)) ";

    private static final String table2Sql = "CREATE TABLE " 
            + table2 + "("
            + table2_row[0] + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + table2_row[1] + " VARCHAR(25))";


private class DatabaseHelper extends SQLiteOpenHelper{

    public DatabaseHelper(Context context) {
        super(context, database_name, null, database_version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(table1Sql);
        db.execSQL(table2Sql);
    }

    @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         db.execSQL("DROP TABLE IF EXISTS "+table1 );
         db.execSQL("DROP TABLE IF EXISTS "+table2 );
         onCreate(db);
      }     
}


public static Uri getTableUri(int i){
    if (i==1){
        return CONTACTS_URI;
    }
    if (i==2){
        return GROUPS_URI;
    }
    else{
        return null;
    }
}

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
    switch (myMatcher.match(uri)){
        case CONTACTS:
            sqlBuilder.setTables(table1);
            break;
        case CONTACT_ID:
            sqlBuilder.setTables(table1);
            sqlBuilder.appendWhere("_id=" + uri.getPathSegments().get(1));
            break;
        case GROUPS:
            sqlBuilder.setTables(table2);
            break;
        case GROUP_ID:
            sqlBuilder.setTables(table2);
            sqlBuilder.appendWhere("_id=" + uri.getPathSegments().get(1));
            break;
        default:
            throw new SQLException("Wrong uri " + uri);
    }
    if (sortOrder == null || sortOrder == "")
        sortOrder = "_id DESC";
    Cursor c = db.query(null, projection, selection, selectionArgs, null, null, sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return null;
}

As mentioned in the title the error message I’m currently getting is Invalid tables when executing the query but I’ve been through a hell of working arround other errors to get here and I’m not sure if I solved them or just walked arround them just to find them again in the future so any error correcting would be greatly appreciated.

LogCat:

01-11 05:43:08.385: E/Trace(930): error opening trace file: No such file or directory (2)
01-11 05:43:08.525: I/ActivityThread(930): Pub hua.it20910.android.provider: hua.it20910.android.MyContentProvider
01-11 05:43:09.515: D/dalvikvm(930): GC_FOR_ALLOC freed 57K, 7% free 2583K/2760K, paused 191ms, total 193ms
01-11 05:43:09.515: I/dalvikvm-heap(930): Grow heap (frag case) to 3.241MB for 635812-byte allocation
01-11 05:43:09.565: D/dalvikvm(930): GC_FOR_ALLOC freed 1K, 6% free 3202K/3384K, paused 43ms, total 43ms
01-11 05:43:09.616: D/dalvikvm(930): GC_CONCURRENT freed <1K, 6% free 3214K/3384K, paused 5ms+13ms, total 52ms
01-11 05:43:09.635: D/AndroidRuntime(930): Shutting down VM
01-11 05:43:09.645: W/dalvikvm(930): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-11 05:43:09.655: E/AndroidRuntime(930): FATAL EXCEPTION: main
01-11 05:43:09.655: E/AndroidRuntime(930): java.lang.RuntimeException: Unable to start activity ComponentInfo{hua.it20910.android/hua.it20910.android.MainActivity}: java.lang.IllegalStateException: Invalid tables
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.os.Looper.loop(Looper.java:137)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-11 05:43:09.655: E/AndroidRuntime(930):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 05:43:09.655: E/AndroidRuntime(930):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 05:43:09.655: E/AndroidRuntime(930):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-11 05:43:09.655: E/AndroidRuntime(930):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-11 05:43:09.655: E/AndroidRuntime(930):  at dalvik.system.NativeStart.main(Native Method)
01-11 05:43:09.655: E/AndroidRuntime(930): Caused by: java.lang.IllegalStateException: Invalid tables
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.database.sqlite.SQLiteDatabase.findEditTable(SQLiteDatabase.java:971)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
01-11 05:43:09.655: E/AndroidRuntime(930):  at hua.it20910.android.MyContentProvider.query(MyContentProvider.java:178)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.content.ContentProvider.query(ContentProvider.java:652)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.content.ContentResolver.query(ContentResolver.java:372)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.content.ContentResolver.query(ContentResolver.java:315)
01-11 05:43:09.655: E/AndroidRuntime(930):  at hua.it20910.android.MainActivity.displayRecords(MainActivity.java:31)
01-11 05:43:09.655: E/AndroidRuntime(930):  at hua.it20910.android.MainActivity.onCreate(MainActivity.java:19)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.Activity.performCreate(Activity.java:5104)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-11 05:43:09.655: E/AndroidRuntime(930):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-11 05:43:09.655: E/AndroidRuntime(930):  ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:04:47+00:00Added an answer on June 17, 2026 at 7:04 am

    As mentioned in the title the error message I’m currently getting is
    Invalid tables when executing the query but I’ve been through a hell
    of working arround other errors to get here and I’m not sure if I
    solved them[…]

    It’s normal that you get that exception because you pass null as the table name when you do the sqlite query in the query method of the ContentProvider, this line:

    Cursor c = db.query(null, projection, selection, selectionArgs, null, null, sortOrder);
    

    The first parameter is the table name and you must supply a valid table name for the query to be successful. So based on the Uri you get choose the proper table and assign a valid table name. Also, what is the purpose of using a SQLiteQueryBuilder in the same query method if you’re going to ignore it completely and simply query the database directly?

    Regarding tutorials, I think you missed the most important one, the official guide for ContentProviders, you even have an example of building one there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I am new to Python so please go easy on me... Secondly, I've
I have a regular expression in my RewriteRule, which is currently working fine. Secondly
I am new to android. I using emulator for my development right now ,
In the code below I firstly try to print the 'normal' way. Secondly I
First off, I'm a Paradox newbie. Secondly, I'm querying a database of a third-party
In Java, assume 3 java application running. a) Firstly, My application running b) Secondly,
Firstly newbie question: What's the difference between a selector and a method? Secondly newbie
Ok first of all what is the difference between these two products? Secondly are
Is there any query which can return me the number of revisions made to
Secondly, I have an SVG form transform in different path using raphaeljs lib. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.