1

stackoverflow,我正在尝试获取消息总数,但仅从少数用户那里得到以下异常。

stackoverflow在以下链接中也提出了这个问题android.database.sqlite.SQLiteException: Can't downgrade database from version 58 to 55 for android sms database

我正在使用以下代码

private void totalSMS()
{
    try{
        Uri allMessages = Uri.parse("content://sms/");
        Cursor c = getContentResolver().query(allMessages, null, null, null, null);
        totalMessages = 0;

        while (c.moveToNext()) 
        {
            String messageBody = c.getString(c.getColumnIndex("body"));
            long messageLength = messageBody.length();
            double numberOfMessages = messageLength / 160.0;
            double numberOfMessagesRoundedUp = Math.ceil(numberOfMessages);

            totalMessages = (int) (totalMessages + numberOfMessagesRoundedUp);
        }
    }catch(Exception e){
        totalMessages = 0;
    }
}

我得到以下crash信息

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from     version 58 to 55
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)

请帮我解开这个谜。

谢谢。

4

0 回答 0