2012-10-08 27 views
0

的。當我使用android 4.0.3我得到一個例外getReadbleDataBase() method.`異常在getReadbleDataBase()SqliteOpenHelper

10-08 11:34:24.163: E/SQLiteOpenHelper(18710): Couldn't open quytech.db for writing (will try read-only): 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): android.database.sqlite.SQLiteException: Can't downgrade database from version 6 to 1 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:325) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:186) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:249) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at com.quytech.androidclient.data.MessageCountProvider.query(MessageCountProvider.java:156) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at android.content.ContentProvider$Transport.query(ContentProvider.java:189) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at android.content.ContentResolver.query(ContentResolver.java:315) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at com.quytech.androidclient.service.SmackableImp$6.processPacket(SmackableImp.java:1781) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at org.jivesoftware.smack.Connection$ListenerWrapper.notifyListener(Connection.java:829) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at org.jivesoftware.smack.PacketReader$ListenerNotification.run(PacketReader.java:463) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
10-08 11:34:24.163: E/SQLiteOpenHelper(18710): at java.lang.Thread.run(Thread.java:864) 

但這是android 2.0.3工作的罰款。

首先,我嘗試從dataBase中獲取查詢。

Cursor cursor = mContentResolver.query(MessageCountProvider.CONTENT_URI, 
         null, MessageCountConstant.JID + " = ? AND " 
         + MessageCountConstant.To_USER + " = ? AND " 
         + MessageCountConstant.DATE + " = ? ", new String [] {mConfig.userName,toJID,date},null); 


       if(cursor.getCount() > 0) 
       { 
        cursor.moveToFirst(); 
        int recieveMessageCountColmnIndex = cursor.getColumnIndexOrThrow(MessageCountConstant.RECIEVE_MESSAGE_COUNT); 
        int sendMessageCountColmnIndex = cursor.getColumnIndexOrThrow(MessageCountConstant.SEND_MESSAGE_COUNT); 
        int dateColumnIndex = cursor.getColumnIndexOrThrow(MessageCountConstant.DATE); 
        String dateDB = cursor.getString(dateColumnIndex); 
        int sendMessageCount = cursor.getInt(sendMessageCountColmnIndex); 
        int reciveMessageCount = cursor.getInt(recieveMessageCountColmnIndex); 

        updateMessageCountInDB(mConfig.userName, toJID, sendMessageCount+1, reciveMessageCount, date); 
       } 
       else 
       { 
        addMessageCountInDB(mConfig.userName, toJID, 1, 0, date); 

       } 

它之後它調用我擴展與ContentProvider。

並調用query()方法。

@Override 
public Cursor query(Uri url, String[] projectionIn, String selection, 
     String[] selectionArgs, String sortOrder) { 
    // TODO Auto-generated method stub 
    SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder(); 
    int match = URI_MATCHER.match(url); 

    switch (match) { 
    case MESSAGES: 
     qBuilder.setTables(TABLE_NAME); 
     break; 
    case MESSAGE_ID: 
     qBuilder.setTables(TABLE_NAME); 
     qBuilder.appendWhere("_id="); 
     qBuilder.appendWhere(url.getPathSegments().get(1)); 
     break; 
    default: 
     throw new IllegalArgumentException("Unknown URL " + url); 
    } 

    String orderBy; 
    if (TextUtils.isEmpty(sortOrder)) { 
     orderBy = ChatConstants.DEFAULT_SORT_ORDER; 
    } else { 
     orderBy = sortOrder; 
    } 

    SQLiteDatabase db = mOpenHelper.getReadableDatabase(); 
    Cursor ret = qBuilder.query(db, projectionIn, selection, selectionArgs, 
      null, null, orderBy); 

    if (ret == null) { 
     infoLog("MessageCountProvider.query: failed"); 
    } else { 
     ret.setNotificationUri(getContext().getContentResolver(), url); 
    } 

    return ret; 
} 







private static class MessageCountDataBaseHelper extends SQLiteOpenHelper { 

private static final String DATABASE_NAME = "quytech.db"; 
private static final int DATABASE_VERSION = 1; 

public MessageCountDataBaseHelper(Context context) { 
    super(context, DATABASE_NAME, null, DATABASE_VERSION); 
} 

@Override 
public void onCreate(SQLiteDatabase db) 
{ 
    if (LogConstants.LOG_DEBUG) { 
     infoLog("creating new chat table"); 
    } 

    db.execSQL("CREATE TABLE " + TABLE_NAME + " (" 

      + MessageCountConstant._ID+ " INTEGER PRIMARY KEY AUTOINCREMENT," 
      + MessageCountConstant.JID + " TEXT," 
      + MessageCountConstant.To_USER + " TEXT," 
      + MessageCountConstant.SEND_MESSAGE_COUNT + " INTEGER," 
      + MessageCountConstant.RECIEVE_MESSAGE_COUNT + " INTEGER," 
      + MessageCountConstant.DATE + " DATE" 

      +");" 

      ); 
} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    infoLog("onUpgrade: from " + oldVersion + " to " + newVersion); 

    infoLog("onUpgrade: from " + oldVersion + " to " + newVersion); 
    switch (oldVersion) { 
    default: 
     db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
     onCreate(db); 
    } 
} 
} 

請幫助我..

+0

把你的代碼放在這裏... –

+2

把你的Database_version改爲6或更高。你不能降級你的數據庫的版本。 – Aprian

+0

嗨Aprian。感謝您的回覆。我提到數據庫版本1。它的工作在除Android版本4.0.3以外的其他Android版本 –

回答

0

錯誤消息說:

無法從6版本降級數據庫1

該設備在當前數據庫有版本6.

如果您的應用無法處理降級(這是API版本11中引入的),則必須通過清除應用的數據或卸載應用來刪除該數據庫。