2017-10-12 3 views
0

SQLiteOpenHelper classeAucun tel tableau trouvé SQLITE Erreur

public class DataDB extends SQLiteOpenHelper { 

    public static final int DATABASE_VERSION = 1; 
    public static final String DATABASE_NAME = "Datas"; 
    private static final String SQL_CREATE_ENTRIES = 
      "CREATE TABLE " + FeedEntry.TABLE_NAME + " (" + 
        FeedEntry.COLUMN_NAME_ID + " INTEGER PRIMARY KEY," + 
        FeedEntry.COLUMN_NAME_NAME + " TEXT," + 
        FeedEntry.COLUMN_NAME_DESC + " TEXT," + 
        FeedEntry.COLUMN_NAME_IMG_URL + " TEXT," + 
        FeedEntry.COLUMN_NAME_PRICE + " TEXT);"; 

    private static final String SQL_DELETE_ENTRIES = 
      "DROP TABLE IF EXISTS " + FeedEntry.TABLE_NAME; 

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

    } 

    @Override 
    public void onCreate(SQLiteDatabase sqLiteDatabase) { 
     Log.e("Syntax",SQL_CREATE_ENTRIES); 
     sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES); 
    } 

    @Override 
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 
     sqLiteDatabase.execSQL(SQL_DELETE_ENTRIES); 
     onCreate(sqLiteDatabase); 
    } 

    @Override 
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     onUpgrade(db, oldVersion, newVersion); 
    } 

} 

Code pour insérer du contenu

ContentValues values = new ContentValues(); 

values.put(FeedEntry.COLUMN_NAME_ID, Integer.parseInt(oneObject.getString("id"))); 
values.put(FeedEntry.COLUMN_NAME_NAME, oneObject.getString("name")); 
values.put(FeedEntry.COLUMN_NAME_DESC, oneObject.getString("desc")); 
values.put(FeedEntry.COLUMN_NAME_IMG_URL, oneObject.getString("img_url")); 
values.put(FeedEntry.COLUMN_NAME_PRICE, oneObject.getString("price")); 

db.insert(FeedEntry.TABLE_NAME, null, values); 

Message d'erreur

10-12 23:20:05.244 19171-19171/com.dkartindia.dkart E/SQLiteLog: (1) no such table: category 
10-12 23:20:05.250 19171-19171/com.dkartindia.dkart E/SQLiteDatabase: Error inserting name=VEGETABLES0 price=20.00 description=King prawns are the most popular species of prawn in Australia, due no doubt to their rich flavour and moist flesh. img_url=http://www.dkartindia.com/image.jpg id=0 
                     android.database.sqlite.SQLiteException: no such table: category (code 1): , while compiling: INSERT INTO category(name,price,description,img_url,id) VALUES (?,?,?,?,?) 
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898) 
                      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509) 
                      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
                      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
                      at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
                      at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1499) 
                      at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1371) 
                      at com.dkartindia.dkart.Activities.Home$2.onResponse(Home.java:114) 
                      at com.dkartindia.dkart.Activities.Home$2.onResponse(Home.java:85) 
                      at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65) 
                      at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 
                      at android.os.Handler.handleCallback(Handler.java:815) 
                      at android.os.Handler.dispatchMessage(Handler.java:104) 
                      at android.os.Looper.loop(Looper.java:194) 
                      at android.app.ActivityThread.main(ActivityThread.java:5717) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:372) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
+0

'aucune table de ce type: nom de table category' introuvable. –

+0

Oui, je le sais. Mais la table de catégories ne crée pas. Public static final String TABLE_NAME = "catégorie"; @IntelliJAmiya –

+0

Même problème si vous désinstallez app? et courir encore une fois. –

Répondre

1

Le problème était dans mon code il y avait un Drop Command. C'est pourquoi après la création de la table, elle tombait. En supprimant les lignes a résolu mon problème.

+1

Heureux de vous voir réparé cela. –