android.database.sqlite.SQLiteException: near "FROM"

 

07-20 00:19:30.496: E/JavaBinder(6807): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
07-20 00:19:30.496: E/JavaBinder(6807): android.database.sqlite.SQLiteException: near "FROM": syntax error: , while compiling: SELECT message_count from threads where thread_id=488 FROM sms ORDER BY date DESC
07-20 00:19:30.496: E/JavaBinder(6807):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:180)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.content.ContentResolver.query(ContentResolver.java:311)
07-20 00:19:30.496: E/JavaBinder(6807):     at com.txrj.sms.manager.SmsDataManager.getMessageCountByThreadId(SmsDataManager.java:167)
07-20 00:19:30.496: E/JavaBinder(6807):     at com.txrj.sms.activity.MessageListActivity$2.onChange(MessageListActivity.java:84)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.database.ContentObserver.dispatchChange(ContentObserver.java:133)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.database.ContentObserver$Transport.onChange(ContentObserver.java:65)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.database.IContentObserver$Stub.onTransact(IContentObserver.java:53)
07-20 00:19:30.496: E/JavaBinder(6807):     at android.os.Binder.execTransact(Binder.java:338)
07-20 00:19:30.496: E/JavaBinder(6807):     at dalvik.system.NativeStart.run(Native Method)

 

public static int getMessageCountByThreadId(Context context, long threadId) {
    Cursor cursor = context.getContentResolver().query(Sms.CONTENT_URI,
            new String[]{"message_count from threads where thread_id="+threadId}, // 必须在末尾添加--
            null, null, null);
    int count = 0;
    if(cursor != null) {
        if(cursor.moveToFirst()){
            count = cursor.getInt(0);
        }
        cursor.close();
    }
    return count;
}

 

07-20 00:24:05.114: E/JavaBinder(7096): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
07-20 00:24:05.114: E/JavaBinder(7096): android.database.sqlite.SQLiteException: no such column: thread_id: , while compiling: SELECT message_count from threads where thread_id=488-- FROM sms ORDER BY date DESC // 将thread_id 改成 _id
07-20 00:24:05.114: E/JavaBinder(7096):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:180)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.content.ContentResolver.query(ContentResolver.java:311)
07-20 00:24:05.114: E/JavaBinder(7096):     at com.txrj.sms.manager.SmsDataManager.getMessageCountByThreadId(SmsDataManager.java:167)
07-20 00:24:05.114: E/JavaBinder(7096):     at com.txrj.sms.activity.MessageListActivity$2.onChange(MessageListActivity.java:84)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.database.ContentObserver.dispatchChange(ContentObserver.java:133)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.database.ContentObserver$Transport.onChange(ContentObserver.java:65)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.database.IContentObserver$Stub.onTransact(IContentObserver.java:53)
07-20 00:24:05.114: E/JavaBinder(7096):     at android.os.Binder.execTransact(Binder.java:338)
07-20 00:24:05.114: E/JavaBinder(7096):     at dalvik.system.NativeStart.run(Native Method)

你可能感兴趣的:(exception)