mardi 8 décembre 2015

Getting SQlite Exception while inserting the data in the form.

I am creating a database application where I have used SQlite. When I put all the details in the input form and hit submit I the app crashes and I get messages like SQlite exception and syntax error near ")" and much more. I have pasted a logcat description. If somebody could solve my issue. It would be very helpful.

12-09 09:46:46.770: E/Trace(8563): error opening trace file: No such file or directory (2)
12-09 09:46:47.350: I/Adreno200-EGL(8563): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.081_msm7627a_JB_REL_2.0.3_CL2820657_release_AU (CL2820657)
12-09 09:46:47.350: I/Adreno200-EGL(8563): Build Date: 01/22/13 Tue
12-09 09:46:47.350: I/Adreno200-EGL(8563): Local Branch: 
12-09 09:46:47.350: I/Adreno200-EGL(8563): Remote Branch: quic/jb_rel_2.0.3
12-09 09:46:47.350: I/Adreno200-EGL(8563): Local Patches: NONE
12-09 09:46:47.350: I/Adreno200-EGL(8563): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.081 +  NOTHING
12-09 09:46:47.440: E/copybit(8563): Error opening frame buffer errno=13 (Permission denied)
12-09 09:46:47.440: W/Adreno200-EGLSUB(8563): <updater_create_surface_state:342>: updater_create_surface_state failed to open copybit, error: -13
12-09 09:46:47.470: D/memalloc(8563): ion: Mapped buffer base:0x5422e000 size:1536000 offset:0 fd:62
12-09 09:46:47.470: D/memalloc(8563): ion: Mapped buffer base:0x50cf4000 size:4096 offset:0 fd:64
12-09 09:46:47.630: D/memalloc(8563): ion: Mapped buffer base:0x54909000 size:1536000 offset:0 fd:67
12-09 09:46:47.630: D/memalloc(8563): ion: Mapped buffer base:0x50d21000 size:4096 offset:0 fd:69
12-09 09:46:49.430: E/copybit(8563): Error opening frame buffer errno=13 (Permission denied)
12-09 09:46:49.440: W/Adreno200-EGLSUB(8563): <updater_create_surface_state:342>: updater_create_surface_state failed to open copybit, error: -13
12-09 09:46:49.440: D/memalloc(8563): ion: Mapped buffer base:0x54c80000 size:1536000 offset:0 fd:72
12-09 09:46:49.440: D/memalloc(8563): ion: Mapped buffer base:0x50d76000 size:4096 offset:0 fd:74
12-09 09:46:49.620: D/memalloc(8563): ion: Mapped buffer base:0x5518f000 size:1536000 offset:0 fd:76
12-09 09:46:49.620: D/memalloc(8563): ion: Mapped buffer base:0x50f55000 size:4096 offset:0 fd:78
12-09 09:46:49.640: D/memalloc(8563): ion: Unmapping buffer  base:0x5422e000 size:1536000
12-09 09:46:49.640: D/memalloc(8563): ion: Unmapping buffer  base:0x50cf4000 size:4096
12-09 09:46:49.640: D/memalloc(8563): ion: Unmapping buffer  base:0x54909000 size:1536000
12-09 09:46:49.640: D/memalloc(8563): ion: Unmapping buffer  base:0x50d21000 size:4096
12-09 09:46:51.090: E/copybit(8563): Error opening frame buffer errno=13 (Permission denied)
12-09 09:46:51.090: W/Adreno200-EGLSUB(8563): <updater_create_surface_state:342>: updater_create_surface_state failed to open copybit, error: -13
12-09 09:46:51.100: D/memalloc(8563): ion: Mapped buffer base:0x5422e000 size:1536000 offset:0 fd:63
12-09 09:46:51.100: D/memalloc(8563): ion: Mapped buffer base:0x50d21000 size:4096 offset:0 fd:66
12-09 09:46:51.180: D/memalloc(8563): ion: Mapped buffer base:0x55434000 size:1536000 offset:0 fd:68
12-09 09:46:51.180: D/memalloc(8563): ion: Mapped buffer base:0x50f82000 size:4096 offset:0 fd:70
12-09 09:46:51.210: D/memalloc(8563): ion: Unmapping buffer  base:0x54c80000 size:1536000
12-09 09:46:51.210: D/memalloc(8563): ion: Unmapping buffer  base:0x50d76000 size:4096
12-09 09:46:51.210: D/memalloc(8563): ion: Unmapping buffer  base:0x5518f000 size:1536000
12-09 09:46:51.210: D/memalloc(8563): ion: Unmapping buffer  base:0x50f55000 size:4096
12-09 09:46:51.630: D/memalloc(8563): ion: Mapped buffer base:0x54b80000 size:1536000 offset:0 fd:72
12-09 09:46:51.640: D/memalloc(8563): ion: Mapped buffer base:0x50d76000 size:4096 offset:0 fd:74
12-09 09:46:52.120: D/memalloc(8563): ion: Mapped buffer base:0x5518f000 size:1536000 offset:0 fd:76
12-09 09:46:52.120: D/memalloc(8563): ion: Mapped buffer base:0x50f55000 size:4096 offset:0 fd:78
12-09 09:46:52.440: D/memalloc(8563): ion: Mapped buffer base:0x515f0000 size:122880 offset:0 fd:81
12-09 09:46:52.440: D/memalloc(8563): ion: Mapped buffer base:0x50fa2000 size:4096 offset:0 fd:83
12-09 09:46:54.400: D/memalloc(8563): ion: Unmapping buffer  base:0x515f0000 size:122880
12-09 09:46:54.400: D/memalloc(8563): ion: Unmapping buffer  base:0x50fa2000 size:4096
12-09 09:46:55.460: E/copybit(8563): Error opening frame buffer errno=13 (Permission denied)
12-09 09:46:55.460: W/Adreno200-EGLSUB(8563): <updater_create_surface_state:342>: updater_create_surface_state failed to open copybit, error: -13
12-09 09:46:55.460: D/memalloc(8563): ion: Mapped buffer base:0x555ab000 size:1064960 offset:0 fd:81
12-09 09:46:55.460: D/memalloc(8563): ion: Mapped buffer base:0x50fa2000 size:4096 offset:0 fd:83
12-09 09:46:55.510: D/memalloc(8563): ion: Mapped buffer base:0x556af000 size:1064960 offset:0 fd:85
12-09 09:46:55.510: D/memalloc(8563): ion: Mapped buffer base:0x512b6000 size:4096 offset:0 fd:87
12-09 09:46:55.560: D/memalloc(8563): ion: Mapped buffer base:0x557b3000 size:1064960 offset:0 fd:89
12-09 09:46:55.570: D/memalloc(8563): ion: Mapped buffer base:0x512b7000 size:4096 offset:0 fd:91
12-09 09:46:56.030: D/memalloc(8563): ion: Mapped buffer base:0x558b7000 size:1064960 offset:0 fd:93
12-09 09:46:56.030: D/memalloc(8563): ion: Mapped buffer base:0x512ff000 size:4096 offset:0 fd:95
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x555ab000 size:1064960
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x50fa2000 size:4096
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x556af000 size:1064960
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x512b6000 size:4096
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x557b3000 size:1064960
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x512b7000 size:4096
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x558b7000 size:1064960
12-09 09:46:56.080: D/memalloc(8563): ion: Unmapping buffer  base:0x512ff000 size:4096
12-09 09:47:02.570: E/SQLiteLog(8563): (1) near ")": syntax error
12-09 09:47:02.640: W/dalvikvm(8563): threadid=1: thread exiting with uncaught exception (group=0x40ccf540)
12-09 09:47:02.700: E/AndroidRuntime(8563): FATAL EXCEPTION: main
12-09 09:47:02.700: E/AndroidRuntime(8563): android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE Vegetable(idt INTEGER PRIMARY KEY,vegtharakari TEXT,tharakariprice TEXT,tharakariweight TEXT,tharakariplace TEXT,)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:909)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:520)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1719)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1650)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at com.ons.veg.dbhelper.onCreate(dbhelper.java:77)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at com.ons.veg.dbhelper.addVegetables(dbhelper.java:96)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at com.ons.veg.Vegform.onClick(Vegform.java:152)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.view.View.performClick(View.java:4102)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.view.View$PerformClick.run(View.java:17085)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.os.Handler.handleCallback(Handler.java:615)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.os.Looper.loop(Looper.java:155)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at android.app.ActivityThread.main(ActivityThread.java:5520)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at java.lang.reflect.Method.invokeNative(Native Method)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at java.lang.reflect.Method.invoke(Method.java:511)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1058)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825)
12-09 09:47:02.700: E/AndroidRuntime(8563):     at dalvik.system.NativeStart.main(Native Method)

package com.ons.veg;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class dbhelper extends SQLiteOpenHelper{

    public static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "Bangalore";
    private static final String TABLE_VEGETABLE = "Vegetable";
    private static final String TABLE_FRUITS = "fruits";


    // Variable = value
    //Vegetable
    private static final String KEY_ID = "idt";
    private static final String KEY_VEGITEMS = "vegtharakari";
    private static final String KEY_PRICE = "tharakariprice";          // when you type key and control spacke it gives full name
    private static final String KEY_WEIGHT = "tharakariweight";
    private static final String KEY_PLACE = "tharakariplace";


    //Fruit
    private static final String KEYF_IDD = "Id";
    private static final String KEYF_FRUITITEMS = "FruitItems";
    private static final String KEYF_PRICE = "Price";
    private static final String KEYF_WEIGHT = "Weight";
    private static final String KEYF_PLACE = "Place";

    private static final String CREATE_TABLE_FRUITS =  "CREATE TABLE " 
            + TABLE_FRUITS
            + "("
            + KEYF_IDD
            + " INTEGER PRIMARY KEY," 
            + KEYF_FRUITITEMS 
            + " TEXT,"
            + KEYF_PRICE 
            + " TEXT,"
            + KEYF_WEIGHT
            + " TEXT," 
            + KEYF_PLACE
            + " TEXT," 
            + " )";


    private static final String CREATE_TABLE_VEGETABLE =  "CREATE TABLE " 
            + TABLE_VEGETABLE
            + "("
            + KEY_ID 
            + " INTEGER PRIMARY KEY," 
            + KEY_VEGITEMS 
            + " TEXT,"
            + KEY_PRICE 
            + " TEXT,"
            + KEY_WEIGHT
            + " TEXT," 
            + KEY_PLACE
            + " TEXT," 
            + " )";


    public dbhelper(Context context) {
        super(context,DATABASE_NAME , null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(CREATE_TABLE_VEGETABLE);
        db.execSQL(CREATE_TABLE_FRUITS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub


        db.execSQL("DROP TABLE IF EXISTS" + TABLE_VEGETABLE );
        db.execSQL("DROP TABLE IF EXISTS" + TABLE_FRUITS );

        onCreate(db);

    }

    public void addVegetables(ModelOne model) {                 


        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_VEGITEMS, model.getVegtharakari());
        values.put(KEY_PRICE, model.getTharakariprice());
        values.put(KEY_WEIGHT, model.getTharakariweight());
        values.put(KEY_PLACE, model.getTharakariplace());

        db.insert(TABLE_VEGETABLE, null, values);

        db.close();

    }

    public void addfruits(ModelTwo model1) {                 


        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues valuess = new ContentValues();
        valuess.put(KEYF_FRUITITEMS, model1.getFruitItems());
        valuess.put(KEYF_PRICE, model1.getPrice());
        valuess.put(KEYF_WEIGHT, model1.getWeight());
        valuess.put(KEYF_PLACE, model1.getPlace());

        db.insert(TABLE_FRUITS, null, valuess);

        db.close();

    }


    public int updatecontact (ModelOne godrej){

        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_VEGITEMS, godrej.getVegtharakari());
        values.put(KEY_PRICE, godrej.getTharakariplace());
        values.put(KEY_WEIGHT, godrej.getTharakariweight());
        values.put(KEY_PLACE, godrej.getTharakariplace());

        // updating row
        return db.update(TABLE_VEGETABLE, values, KEY_ID + " = ?",
                new String[] { String.valueOf(godrej.getIdt()) });
    }

    public int updatefruits (ModelTwo godrej1){

        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEYF_FRUITITEMS, godrej1.getFruitItems());
        values.put(KEYF_PRICE, godrej1.getPrice());
        values.put(KEYF_WEIGHT, godrej1.getWeight());
        values.put(KEYF_PLACE, godrej1.getPlace());


        // updating row
        return db.update(TABLE_FRUITS, values, KEY_ID + " = ?",
                new String[] { String.valueOf(godrej1.getId()) });
    }

    public void deletecontact (long id){

        SQLiteDatabase db = this.getWritableDatabase();

        db.delete(TABLE_VEGETABLE, KEY_ID + " = ?",
                new String[] { String.valueOf(id) });
        db.close();

    }

    public void deletefruits (long id){

        SQLiteDatabase db = this.getWritableDatabase();

        db.delete(TABLE_FRUITS, KEY_ID + " = ?",
                new String[] { String.valueOf(id) });
        db.close();

    }

 /**    private void printdatabase() {
        // TODO Auto-generated method stub

        SQLiteDatabase db = this.getReadableDatabase();
        String selectQuery = "SELECT  * FROM " + TABLE_VEGETABLE;
        Cursor cursor = db.rawQuery(selectQuery, null); 

        if (cursor.moveToFirst()){

            System.out.println("Vegetable" + cursor.getString(0));
            System.out.println("Price" + cursor.getString(1));
            System.out.println("Weight" + cursor.getString(2));
            System.out.println("Place" + cursor.getString(3));
        }

        This method is for printing and checking in the logcat

    } **/


    public List<ModelOne> getAllContacts() {
        List<ModelOne> contactListveg = new ArrayList<ModelOne>();  // Array list created to hold the data from database ( rows).
        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_VEGETABLE;

        SQLiteDatabase db = this.getWritableDatabase(); //this is requesting database to allow to write some data to it.
        Cursor cursor = db.rawQuery(selectQuery, null);  // cr
        // we can write here as db.close() (if required). Manipulating data with cursor is very effiient. 

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                ModelOne contact = new ModelOne();
                contact.setVegtharakari(cursor.getString(0));
                contact.setTharakariprice(cursor.getString(1));
                contact.setTharakariweight(cursor.getString(2));
                contact.setTharakariplace(cursor.getString(3));

                // Adding contact to list
                contactListveg.add(contact);
            } while (cursor.moveToNext());             // do this untill the while condition is satisfied. keep repeating the task
            //
        }

        // return contact list
        return contactListveg;
    }

    public List<ModelTwo> getAllContactsTwo() {
        List<ModelTwo> contactListfruits = new ArrayList<ModelTwo>();  // Array list created to hold the data from database ( rows).
        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_FRUITS;

        SQLiteDatabase db = this.getWritableDatabase(); //this is requesting database to allow to write some data to it.
        Cursor cursor = db.rawQuery(selectQuery, null);  // cr
        // we can write here as db.close() (if required). Manipulating data with cursor is very effiient. 

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) 
            do {
                ModelTwo contact = new ModelTwo();
                contact.setFruitItems(cursor.getString(0));
                contact.setPrice(cursor.getString(1));
                contact.setWeight(cursor.getString(2));
                contact.setPlace(cursor.getString(3));

                // Adding contact to list
                contactListfruits.add(contact);
            } while (cursor.moveToNext());             // do this untill the while condition is satisfied. keep repeating the task
        //


        // return contact list
        return contactListfruits;
    }


}

Aucun commentaire:

Enregistrer un commentaire