سؤال

My application keeps forceclosing when I try to view the class that is holding my database holder. I get an error on the onCreate() method of my database. I have one application that uses this same database writin pretty much the same way the only difference is that I am trying to click through a menu option instead of a regular button, I don't know if that will effect the problem in anyway. If some one could tell me what is wrong that would be nice. thank you.

LOG CAT ERROR UPDATED

11-28 22:06:01.951: E/AndroidRuntime(19544): FATAL EXCEPTION: main
11-28 22:06:01.951: E/AndroidRuntime(19544): java.lang.RuntimeException: Unable to start activity ComponentInfo{http.www.hotapp.com.timeandlocation/http.www.hotapp.com.timeandlocation.db.DatabaseViewer}: android.database.sqlite.SQLiteException: near "IS": syntax error: CREATE TABLE dbtable (_id INTEGER PRIMARY KEY AUTOINCREMENT, latitude TEXT IS NOT NULL, longitude TEXT IS NOT NULL, time TEXT IS NOT NULL, date TEXT IS NOT NULL);
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.os.Looper.loop(Looper.java:123)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread.main(ActivityThread.java:4627)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at java.lang.reflect.Method.invokeNative(Native Method)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at java.lang.reflect.Method.invoke(Method.java:521)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at dalvik.system.NativeStart.main(Native Method)
11-28 22:06:01.951: E/AndroidRuntime(19544): Caused by: android.database.sqlite.SQLiteException: near "IS": syntax error: CREATE TABLE dbtable (_id INTEGER PRIMARY KEY AUTOINCREMENT, latitude TEXT IS NOT NULL, longitude TEXT IS NOT NULL, time TEXT IS NOT NULL, date TEXT IS NOT NULL);
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at http.www.hotapp.com.timeandlocation.db.Database$DatabaseHelper.onCreate(Database.java:35)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at http.www.hotapp.com.timeandlocation.db.Database.open(Database.java:63)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at http.www.hotapp.com.timeandlocation.db.DatabaseViewer.onCreate(DatabaseViewer.java:26)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-28 22:06:01.951: E/AndroidRuntime(19544):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

onCreate METHOD INSIDE DATABASE CLASS

@Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(" CREATE TABLE " + DATABASE_TABLE + " (" +
        KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        KEY_LATITUDE + " TEXT IS NOT NULL, " +
        KEY_LONGITUDE + " TEXT IS NOT NULL, " +
        KEY_TIME + " TEXT IS NOT NULL, " +
        KEY_DATE + " TEXT IS NOT NULL);");


    }

VIEWER CLASS

public class DatabaseViewer extends Activity{

private TextView dbla;
private TextView dblo;
private TextView dbti;
private TextView dbda;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.database);


    dbln = (TextView) findViewById(R.id.dblo);
    dbti = (TextView) findViewById(R.id.dbti);
    dbda = (TextView) findViewById(R.id.dbda);

    dbla = (TextView) findViewById(R.id.dbla);
    Database info = new Database(this);
    info.open();
    String data = info.latData();
    info.close();
    dblt.setText(data);
}

 }
هل كانت مفيدة؟

المحلول

Try this:

1) remove "IS"

2) remove ';' at the end

نصائح أخرى

From some sqlite documentation:

A set of SQL constraints for each table. SQLite supports UNIQUE, NOT NULL, CHECK and FOREIGN KEY constraints.

Take out the 'IS' portion of 'IS NOT NULL' to read 'TEXT NOT NULL'

The issue is with Table Create Query..

Remove "IS".. that's what Logcat also says

Do one thing.. Use Firefox with SQLITE Manager.. Try your SQLITE queries over there on receiving such errors..

FYI : http://code.google.com/p/sqlite-manager/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top