با سلام بنده هنگام ارتقای ورژن دیتا ببیس برنامه با خطای زیر مواجه میشم ک حس میکنم بخاطر خالی بودن دیتا بیس ایجاد شده هست که هیچ ستونی شاید اایجاد نشده !
متن خطا :
این هم کد داخل کلاس دیتا بیس هست
قبل از آپدیت ورژن هیچ مشکلی از نظر کارکرد نیست . تشکر
متن خطا :
05-09 15:05:12.507 32396-32396/? E/Zygote: v2 05-09 15:05:12.508 32396-32396/? E/Zygote: accessInfo : 0 05-09 15:05:15.482 32396-32396/com.example.mahdi.car2 E/SQLiteLog: (1) no such table: learndata 05-09 15:05:15.489 32396-32396/com.example.mahdi.car2 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mahdi.car2, PID: 32396 android.database.sqlite.SQLiteException: no such table: learndata (code 1): , while compiling: SELECT * FROM learndata ################################################################# Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (no such table: learndata (code 1): , while compiling: SELECT * FROM learndata) ################################################################# at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1005) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:570) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59) at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1618) at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1557) at com.example.mahdi.car2.DataBaseAccess.getid(DataBaseAccess.java:192) at com.example.mahdi.car2.learnClass.LoadPanel(learnClass.java:51) at com.example.mahdi.car2.learnClass$1.run(learnClass.java:40) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
این هم کد داخل کلاس دیتا بیس هست
package com.example.mahdi.car2;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Mahdi on 4/2/2017.
*/
public class DataBaseAccess extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "mydatabase.db";
private static final int DATABASE_VERSION = 3;
//---------------------------------------------------------DataCar
private static final String DataCar_COLUMN_ID = "id";
private static final String DataCar_COLUMN_Car = "car";
private static final String DataCar_COLUMN_Tipe = "tipe";
private static final String DataCar_COLUMN_YearCar = "yearcar";
private static final String DataCar_COLUMN_Color = "color";
private static final String DataCar_COLUMN_Kilometer = "kilometer";
private static final String DataCar_COLUMN_Reminder = "reminder";
private static final String DataCar_COLUMN_Image = "image";
//---------------------------------------------------------LearnData
private static final String LearnData_COLUMN_ID = "id";
private static final String LearnData_COLUMN_subject = "subject";
private static final String LearnData_COLUMN_Note = "note";
private static final String LearnData_COLUMN_Note2 = "note2";
private static final String LearnData_COLUMN_Note3 = "note3";
//---------------------------------------------------------ServiceCar
private static final String ServiceCar_COLUMN_ID = "id";
private static final String ServiceCar_COLUMN_CarSelect = "CarSelect";
private static final String ServiceCar_COLUMN_RoghanMotor = "RoghanMotor";
private static final String ServiceCar_COLUMN_FilterRoghan = "FilterRoghan";
private static final String ServiceCar_COLUMN_FilterHava = "FilterHava";
private static final String ServiceCar_COLUMN_FilterBenzin = "FilterBenzin";
private static final String ServiceCar_COLUMN_FilterKabin = "FilterKabin";
private static final String ServiceCar_COLUMN_MayeShisheShor = "MayeShisheShor";
private static final String ServiceCar_COLUMN_Sham = "Sham";
private static final String ServiceCar_COLUMN_LentJelo = "LentJelo";
private static final String ServiceCar_COLUMN_LentAghab = "LentAghab";
private static final String ServiceCar_COLUMN_TasmeTime = "TasmeTime";
private static final String ServiceCar_COLUMN_TasmeDinam = "TasmeDinam";
private static final String ServiceCar_COLUMN_Battery = "Battery";
private static final String ServiceCar_COLUMN_Lastic = "Lastic";
private static final String ServiceCar_COLUMN_MayeRadiat = "MayeRadiat";
private static final String ServiceCar_COLUMN_GasKoler = "GasKoler";
private static final String ServiceCar_COLUMN_RoghanTormoz = "RoghanTormoz";
private static final String ServiceCar_COLUMN_RoghanHydrolic = "RoghanHydrolic";
private static final String ServiceCar_COLUMN_RoghanGearbox = "RoghanGearbox";
private static final String ServiceCar_COLUMN_ShosteshoAnjector = "ShosteshoAnjector";
private static final String ServiceCar_COLUMN_Catalizor = "Catalizor";
private static final String ServiceCar_COLUMN_FesharbadLastic = "FesharbadLastic";
private static final String ServiceCar_COLUMN_JabejaiLastic = "JabejaiLastic";
private static final String ServiceCar_COLUMN_Sokht = "Sokht";
private static final String ServiceCar_COLUMN_insurance = "insurance";
private static final String ServiceCar_COLUMN_insurancebody = "insurancebody";
private static final String ServiceCar_COLUMN_inspection = "inspection";
private static final String ServiceCar_COLUMN_expirationcertificated = "expirationcertificated";
private static final String ServiceCar_COLUMN_other = "other";
//---------------------------------------------------------VideoData
private static final String VideoData_COLUMN_ID = "id";
private static final String VideoData_COLUMN_Title = "title";
private static final String VideoData_COLUMN_Link = "link";
SQLiteDatabase db ;
private static final String TABLE_CREATE_DataCar = "create table " + "datacar"
+ " (" + DataCar_COLUMN_ID + " integer primary key not null, "
+ DataCar_COLUMN_Car + " text not null, "
+ DataCar_COLUMN_Tipe + " text not null, "
+ DataCar_COLUMN_YearCar + " text not null, "
+ DataCar_COLUMN_Color + " text not null, "
+ DataCar_COLUMN_Kilometer + " text not null, "
+ DataCar_COLUMN_Reminder + " text not null, "
+ DataCar_COLUMN_Image + " text not null);";
private static final String TABLE_CREATE_LearnData = "create table " + "datacar"
+ " (" + LearnData_COLUMN_ID + " integer primary key not null, "
+ LearnData_COLUMN_subject + " text not null, "
+ LearnData_COLUMN_Note + " text not null, "
+ LearnData_COLUMN_Note2 + " text not null, "
+ LearnData_COLUMN_Note3 + " text not null);";
private static final String TABLE_CREATE_ServiceCar = "create table " + "datacar"
+ " (" + ServiceCar_COLUMN_ID + " integer primary key not null, "
+ ServiceCar_COLUMN_CarSelect + " text not null, "
+ ServiceCar_COLUMN_RoghanMotor + " text not null, "
+ ServiceCar_COLUMN_FilterRoghan + " text not null, "
+ ServiceCar_COLUMN_FilterHava + " text not null, "
+ ServiceCar_COLUMN_FilterBenzin + " text not null, "
+ ServiceCar_COLUMN_FilterKabin + " text not null, "
+ ServiceCar_COLUMN_MayeShisheShor + " text not null, "
+ ServiceCar_COLUMN_Sham + " text not null, "
+ ServiceCar_COLUMN_LentJelo + " text not null, "
+ ServiceCar_COLUMN_LentAghab + " text not null, "
+ ServiceCar_COLUMN_TasmeTime + " text not null, "
+ ServiceCar_COLUMN_TasmeDinam + " text not null, "
+ ServiceCar_COLUMN_Battery + " text not null, "
+ ServiceCar_COLUMN_Lastic + " text not null, "
+ ServiceCar_COLUMN_MayeRadiat + " text not null, "
+ ServiceCar_COLUMN_GasKoler + " text not null, "
+ ServiceCar_COLUMN_RoghanTormoz + " text not null, "
+ ServiceCar_COLUMN_RoghanHydrolic + " text not null, "
+ ServiceCar_COLUMN_RoghanGearbox + " text not null, "
+ ServiceCar_COLUMN_ShosteshoAnjector + " text not null, "
+ ServiceCar_COLUMN_Catalizor + " text not null, "
+ ServiceCar_COLUMN_FesharbadLastic + " text not null, "
+ ServiceCar_COLUMN_JabejaiLastic + " text not null, "
+ ServiceCar_COLUMN_Sokht + " text not null, "
+ ServiceCar_COLUMN_insurance + " text not null, "
+ ServiceCar_COLUMN_insurancebody + " text not null, "
+ ServiceCar_COLUMN_inspection + " text not null, "
+ ServiceCar_COLUMN_expirationcertificated + " text not null, "
+ ServiceCar_COLUMN_other + " text not null);";
private static final String TABLE_CREATE_VideoData = "create table " + "datacar"
+ " (" + VideoData_COLUMN_ID + " integer primary key not null, "
+ VideoData_COLUMN_Title + " text not null, "
+ VideoData_COLUMN_Link + " text not null);";
public void onCreateTable(SQLiteDatabase db1) {
db.execSQL(TABLE_CREATE_DataCar);
db.execSQL(TABLE_CREATE_LearnData);
db.execSQL(TABLE_CREATE_ServiceCar);
db.execSQL(TABLE_CREATE_VideoData);
this.db = db1;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + "datacar");
db.execSQL("DROP TABLE IF EXISTS " + "learndata");
db.execSQL("DROP TABLE IF EXISTS " + "servicecar");
db.execSQL("DROP TABLE IF EXISTS " + "videodata");
// Create tables again
onCreateTable(db);
Log.d("---> Upgrade DataBase","Success");
}
/* public void insertEntry(DiaryEntries entries){
db = this.getWritableDatabase();
ContentValues values = new ContentValues();
String query = "SELECT * FROM " + TABLE_NAME;
Cursor cursor = db.rawQuery(query, null);
int count = cursor.getCount();
values.put(DataCar_COLUMN_ID, count);
values.put(DataCar_COLUMN_TITLE, entries.getTitle());
values.put(DataCar_COLUMN_DETAILS, entries.getDetails());
values.put(DataCar_COLUMN_SAVE_DATE, entries.getDate());
values.put(DataCar_COLUMN_USER_ID, entries.getUser_id());
db.insert(TABLE_NAME, null, values);
db.close();
}*/
//
SQLiteDatabase sqLiteDatabase = getWritableDatabase();
public DataBaseAccess(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public List<String> getid(int getid,String SelectTable) {
List<String> list = new ArrayList<>();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT * FROM "+SelectTable,null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
list.add(cursor.getString(getid));
cursor.moveToNext();
}
cursor.close();
return list;
}
public List<String> Selectid(int getid,String SelectTable,String SelectColumn,int Contains) {
List<String> list = new ArrayList<>();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT * FROM "+SelectTable+" WHERE "+SelectColumn+"="+Contains,null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
//for(int i=0;i<cursor.getColumnCount();i++) {
list.add(cursor.getString(getid));
//}
cursor.moveToNext();
}
cursor.close();
return list;
}
public List<String> CommandData(int getid,String Command) {
List<String> list = new ArrayList<>();
Cursor cursor = sqLiteDatabase.rawQuery(Command,null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
//for(int i=0;i<cursor.getColumnCount();i++) {
list.add(cursor.getString(getid));
//}
cursor.moveToNext();
}
cursor.close();
return list;
}
public void DeleteDatabase(String TableName,String Column,String Data){
sqLiteDatabase.delete(TableName, Column+"='"+Data+"'", null);
}
public void UpdateDatabase(String TableName,String id,String Column,String Data,String Replace) {
ContentValues cv = new ContentValues();
cv.put(Column, Replace);
sqLiteDatabase.update(TableName, cv,"id='"+id+"' AND "+ Column+"='"+Data+"'", null);
}
public void UpdateCarDatabase(String id,String Update_Car,String Update_Tipe,String Update_Yearcar,String Update_Color,String Update_Reminder,String Update_Image) {
ContentValues cv = new ContentValues();
cv.put("car", Update_Car);
cv.put("tipe", Update_Tipe);
cv.put("yearcar", Update_Yearcar);
cv.put("color", Update_Color);
cv.put("reminder", Update_Reminder);
cv.put("image", Update_Image);
sqLiteDatabase.update("datacar", cv,"id='"+id+"'", null);
}
public void UpdateKilometer(String TableName,String id,String Column,String Replace) {
ContentValues cv = new ContentValues();
cv.put(Column, Replace);
sqLiteDatabase.update(TableName, cv,"id='"+id+"'", null);
}
public void InsertNewCarDatabase(String TableName,String Car,String Tipe,String YearCar,String Color,String Kilometer,String Reminder) {
ContentValues cv = new ContentValues();
cv.put("car", Car);
cv.put("tipe", Tipe);
cv.put("yearcar", YearCar);
cv.put("color", Color);
cv.put("kilometer", Kilometer);
cv.put("reminder", Reminder);
sqLiteDatabase.insert(TableName, null, cv);
}
public void InsertNewServiceDatabase(String TableName,String CarSelect,String RoghanMotor,String FilterRoghan,String FilterHava,String FilterBenzin,String FilterKabin,String MayeShisheShor,String Sham,String LentJelo,String LentAghab,String TasmeTime,String TasmeDinam,String Battery,String Lastic,String MayeRadiat,String GasKoler,String RoghanTormoz,String RoghanHydrolic,String RoghanGearbox,String ShosteshoAnjector,String Catalizor,String FesharbadLastic,String JabejaiLastic,String Sokht ,String Insurance,String InsuranceBody,String Inspection,String ExpirationCertificate,String Other) {
ContentValues cv = new ContentValues();
cv.put("CarSelect", CarSelect);
cv.put("RoghanMotor", RoghanMotor);
cv.put("FilterRoghan", FilterRoghan);
cv.put("FilterHava", FilterHava);
cv.put("FilterBenzin", FilterBenzin);
cv.put("FilterKabin", FilterKabin);
cv.put("MayeShisheShor", MayeShisheShor);
cv.put("Sham", Sham);
cv.put("LentJelo", LentJelo);
cv.put("LentAghab", LentAghab);
cv.put("TasmeTime", TasmeTime);
cv.put("TasmeDinam", TasmeDinam);
cv.put("Battery", Battery);
cv.put("Lastic", Lastic);
cv.put("MayeRadiat", MayeRadiat);
cv.put("GasKoler", GasKoler);
cv.put("RoghanTormoz", RoghanTormoz);
cv.put("RoghanHydrolic", RoghanHydrolic);
cv.put("RoghanGearbox", RoghanGearbox);
cv.put("ShosteshoAnjector", ShosteshoAnjector);
cv.put("Catalizor", Catalizor);
cv.put("FesharbadLastic", FesharbadLastic);
cv.put("JabejaiLastic", JabejaiLastic);
cv.put("Sokht", Sokht);
cv.put("insurance", Insurance);
cv.put("insurancebody", InsuranceBody);
cv.put("inspection", Inspection);
cv.put("expirationcertificated", ExpirationCertificate);
cv.put("other", Other);
sqLiteDatabase.insert(TableName, null, cv);
}
}
قبل از آپدیت ورژن هیچ مشکلی از نظر کارکرد نیست . تشکر