Android SQL app unfortunately app has stopped

I have followed the following tutorial (https://www.youtube.com/watch?v=p8TaTgr4uKM) to create an SQL database app, unfortunately i am having an issue where the app doesn't open, can anyone help and see if i'm doing something wrong.

This is the SQL Code package com.example.sqltest2;

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 = "products.db";
public static final String TABLE_NAME = "productstable.db";
public static final String COL_1 = "ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "Aisle";
public static final String COL_4 = "LOC";

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME,null, 1);
    SQLiteDatabase db = this.getWritableDatabase();
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table" + TABLE_NAME +" (ID INTEGER PRIMAY KEY    AUTOINCREMENT, NAME TEXT, Aisle INTEGER, LOC INTEGER)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
    onCreate(db);
}

}

The Logcat points to syntax error on
public void onCreate(SQLiteDatabase db) { db.execSQL("create table" + TABLE_NAME +" (ID INTEGER PRIMAY KEY AUTOINCREMENT, NAME TEXT, Aisle INTEGER, LOC INTEGER)"); }


Edit: The main issue is probably what @Marc B pointed out, PRIMAY should be PRIMARY .

I also noticed this:

Your TABLE_NAME has .db in it.

Change this:

public static final String TABLE_NAME = "productstable.db";

To this:

public static final String TABLE_NAME = "productstable";

In addition to Marc's and Daniel's responses; your CREATE statement needs a space.
"create table" + TABLE_NAME +" will produce something like create tableproductstable . Place a space after table to have "create table " + TABLE_NAME + ...

链接地址: http://www.djcxy.com/p/31968.html

上一篇: 反编译APK并在您的应用中使用部分代码是合法的

下一篇: Android SQL应用不幸的应用已停止