当我尝试查看持有数据库持有者的类时,我的应用程序保持强制关闭。我的数据库的onCreate()方法出错了。我有一个应用程序使用相同的数据库写入几乎相同的方式唯一的区别是我试图点击菜单选项而不是常规按钮,我不知道这是否会影响问题。如果有人可以告诉我什么是错的,那会很好。谢谢。
更新了LOG CAT错误
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);
}
}
答案 0 :(得分:1)
试试这个:
1)删除“IS”
2)删除';'最后
答案 1 :(得分:0)
每个表的一组SQL约束。 SQLite支持UNIQUE,NOT NULL,CHECK和FOREIGN KEY约束。
取出'IS NOT NULL'的'IS'部分,读取'TEXT NOT NULL'
答案 2 :(得分:0)
问题在于表创建查询..
删除“IS”..这就是Logcat所说的
做一件事..将Firefox与SQLITE Manager一起使用..在接收此类错误时尝试使用SQLITE查询..