Richard
Richard

Reputation: 56

Accessing Call Log on Galaxy Devices: SQLiteException: no such column: Calls._ID

I am facing a problem on Samsung Galaxy devices.

My application is trying to access the call long on the phone.

It works fine on most devices but not Samsung Galaxy devices, any one know how to solve the problem?

    android.database.sqlite.SQLiteException: no such column: Calls._ID (code 1): , 
    while compiling: SELECT _id, number, date, duration, type FROM logs WHERE 
    (logs.logtype=100 OR logs.logtype=110 OR logs.logtype=900 OR logs.logtype=500 OR
    logs.logtype=800 OR logs.logtype=120 OR logs.logtype=510 OR logs.logtype=1000 OR
    (logs.logtype=200 AND number NOT IN (SELECT number FROM logs WHERE number LIKE 
    '%@%')) OR logs.logtype=300) AND ((((type != 4)) AND (logtype=100 OR logtype=500))) 
    ORDER BY Calls._ID DESC
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:184)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at com.example.minutes.MainActivity.onCreateOptionsMenu(MainActivity.java:140)
    at android.app.Activity.onCreatePanelMenu(Activity.java:2571)
    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:455)
    at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:829)
    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3192)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
    at dalvik.system.NativeStart.main(Native Method)

Here are the code I used to access the call log

     String columns[]=new String[] {
             CallLog.Calls._ID, 
             CallLog.Calls.NUMBER, 
             CallLog.Calls.DATE, 
             CallLog.Calls.DURATION, 
             CallLog.Calls.TYPE};
     Cursor c;
    c = getContentResolver().query(Uri.parse("content://call_log/calls"),
                   columns, null, null, "Calls._ID DESC");

Upvotes: 0

Views: 418

Answers (2)

Stelio
Stelio

Reputation: 57

try ORDER BY "_id DESC", not ORDER BY Calls._ID DESC. I had the same issue with the kit kat 4.4.2. Haven't tested it out on other versions, but it should work fine on all versions.

Upvotes: 0

NEERAJ SWARNKAR
NEERAJ SWARNKAR

Reputation: 437

Though your code snippet is not complete, but I assume you are trying to get column from a cursor. Even though the column names are correct, you are getting exception. Please ensure two things: 1. Cursor.getCount() > 0 2. If above condition is true, move to first record i.e. Cursor.moveToFirst();

This must solve your problem.

Upvotes: 1

Related Questions