title: Android SMS SQLite Crash "Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 58 to 55"
body: <p>Hi <code>stackoverflow</code> I'm trying to get the total number of messages, but I'm getting the following exception from few users only.</p>
  
  <p>And also this question has been asked in <code>stackoverflow</code> in the following link <a href="https://stackoverflow.com/questions/16669499/android-database-sqlite-sqliteexception-cant-downgrade-database-from-version-5">android.database.sqlite.SQLiteException: Can&#39;t downgrade database from version 58 to 55 for android sms database</a></p>
  
  <p>I'm using the following code</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>and I'm getting following <code>crash</code> information</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Please help me to solve this riddle.</p>
  
  <p>Thanks.</p>