I am new here (and in the programming in general) and was hoping you could help me with this. When I try to start the app, it just "Stops working". I looked through all the similar questions here, but couldn't solve it. This is my code:
package com.example.me.mac_xyz;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "mac.db";
public static final String TABLE_NAME = "1";
public static final String COL_1 = "NUMBER";
public static final String COL_2 = "MAC";
public static final String COL_3 = "X";
public static final String COL_4 = "Y";
public static final String COL_5 = "Z";
/* Constructor*/
public DatabaseHelper(Context context) { /*, String name, SQLiteDatabase.CursorFactory factory, int version*/
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table" + TABLE_NAME +"(NUMBER INTEGER PRIMARY,MAC TEXT,X INTEGER,Y INTEGER,Z INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" +TABLE_NAME);
onCreate(db);
}
And this is in the log:
11-12 22:34:47.706 31044-31044/com.example.me.mac_xyz E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.me.mac_xyz, PID: 31044
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.me.mac_xyz/com.example.me.mac_xyz.MainActivity}: android.database.sqlite.SQLiteException: near "table1": syntax error (code 1): , while compiling: create table1(NUMBER INTEGER PRIMARY,MAC TEXT,X INTEGER,Y INTEGER,Z INTEGER)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "table1": syntax error (code 1): , while compiling: create table1(NUMBER INTEGER PRIMARY,MAC TEXT,X INTEGER,Y INTEGER,Z INTEGER)
* * *
What did I do wrong?