2017-10-19 10 views
-1

投票アプリケーションが忙しく、登録した人のアドレス情報を保存するためにテーブルを既存のデータベースに追加しようとしましたが、アプリケーションを実行するとエラーが発生します私の電話のどこで私がログインをクリックするかボタンを登録するだけでアプリがクラッシュする、私はログ猫を使用したが、私は新しい時間アンドロイドプログラマーなので、私は自分のエラーを知らない。私が手にエラーがこれです:既存のSQLiteデータベースにテーブルを追加する

10-19 14:58:52.170 29644-29644/com.example.loginregisterwithsqlite E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.example.loginregisterwithsqlite, PID: 29644 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loginregisterwithsqlite/com.example.loginregisterwithsqlite.LoginAndRegistrion}: android.database.sqlite.SQLiteException: near "tableADDRESS": syntax error (code 1): , while compiling: create tableADDRESS(ID integer primary key autoincrement,PROVINCE text,MUNICIPALITY text,STREET text,CITY text,FLAT text,TRIBE text,SUBURB text,TOWN text,POST text) 
################################################################# 
Error Code : 1 (SQLITE_ERROR) 
Caused By : SQL(query) error or missing database. 
    (near "tableADDRESS": syntax error (code 1): , while compiling: create tableADDRESS(ID integer primary key autoincrement,PROVINCE text,MUNICIPALITY text,STREET text,CITY text,FLAT text,TRIBE text,SUBURB text,TOWN text,POST text)) 
################################################################# 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008) 
    at android.app.ActivityThread.-wrap14(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6688) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
Caused by: android.database.sqlite.SQLiteException: near "tableADDRESS": syntax error (code 1): , while compiling: create tableADDRESS(ID integer primary key autoincrement,PROVINCE text,MUNICIPALITY text,STREET text,CITY text,FLAT text,TRIBE text,SUBURB text,TOWN text,POST text) 
################################################################# 
Error Code : 1 (SQLITE_ERROR) 
Caused By : SQL(query) error or missing database. 
    (near "tableADDRESS": syntax error (code 1): , while compiling: create tableADDRESS(ID integer primary key autoincrement,PROVINCE text,MUNICIPALITY text,STREET text,CITY text,FLAT text,TRIBE text,SUBURB text,TOWN text,POST text)) 
################################################################# 
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1005) 
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:570) 
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59) 
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1976) 
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1907) 
    at com.example.loginregisterwithsqlite.DataBaseHelper.onCreate(DataBaseHelper.java:16) 
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251) 
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163) 
    at com.example.loginregisterwithsqlite.LoginDataBaseAdapter.open(LoginDataBaseAdapter.java:44) 
    at com.example.loginregisterwithsqlite.LoginAndRegistrion.onCreate(LoginAndRegistrion.java:38) 
    at android.app.Activity.performCreate(Activity.java:6912) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900) 
    ... 9 more 

と、次のようにデータベースにテーブルに挿入するための私のコードは次のとおりです。

public class LoginDataBaseAdapter { 

static final String DATABASE_NAME = "votersystem.db"; 
static final int DATABASE_VERSION = 1; 
public static final int NAME_COLUMN = 4; 

static final String CREATE_ADDRESS_TABLE = "create table"+"ADDRESS"+ 
     "("+"ID integer primary key autoincrement,"+"PROVINCE text," +"MUNICIPALITY text,"+"STREET text,"+"CITY text,"+"FLAT text,"+"TRIBE text,"+"SUBURB text,"+"TOWN text,"+"POST text) "; 

static final String CREATE_LOGIN_TABLE = "create table "+"LOGIN"+ 
     "(" +"ID integer primary key autoincrement,"+"UNAME text," +"EMAIL text,"+"IDNUMBER text,"+"UPHONE text,"+"DIS text," +"PASSWORD text,"+"REPASSWORD text,"+ "SECURITYHINT text) "; 

static final String CREATE_ADMIN_TABLE = "create table "+"ADMIN"+ 
     "(" +"ID integer primary key autoincrement,"+ "FIRSTNAME text,"+"LASTNAME text,"+"PARTY text,"+ "SYMBOL text) "; 

static final String CREATE_REPORT_TABLE = "create table "+"REPORT"+"(" +"ID integer primary key autoincrement,"+ "FULLNAME text,"+"PARTY text"+")"; 
public SQLiteDatabase db; 
private final Context context; 
private DataBaseHelper dbHelper; 
private Cursor mCursor; 

public LoginDataBaseAdapter(Context _context) 
{ 
    context = _context; 
    dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION); 

} 
public LoginDataBaseAdapter open() throws SQLException 
{ 
    db = dbHelper.getWritableDatabase(); 
    return this; 
} 
public void close() 
{ 
    db.close(); 
} 

public SQLiteDatabase getDatabaseInstance() 
{ 
    return db; 
} 

public void insertEntry(String Prov, String Mun, String str, String cty, String flt, String trb, String sburb, String twn, String pst) 
{ 
    ContentValues newValues = new ContentValues(); 
    newValues.put("PROVINCE",Prov); 
    newValues.put("MUNICIPALITY",Mun); 
    newValues.put("STREET",str); 
    newValues.put("CITY",cty); 
    newValues.put("FLAT",flt); 
    newValues.put("TRIBE",trb); 
    newValues.put("SUBURB",sburb); 
    newValues.put("TOWN",twn); 
    newValues.put("POST",pst); 

    db.insert("ADDRESS", null, newValues); 
} 

私のエラーがであるCREATE_ADDRESS_TABLE誰かが私を助けることができるしてください?

+0

あなたは 'table ADDRESS'を' table ADDRESS'に変更する必要があります。 - > '"テーブルを作成 "+"アドレス "' – FlanschiFox

答えて

2

あなたのあなたはスペースが不足しているため、クエリは、間違っています:

"テーブルの作成" + "アドレス" +

に変更し、それを:

"create table "+"ADDRESS" 

あなたがいますあなたの他のクエリで正しいことをしているので、気づかなかった小さな間違いかもしれません。 SQL(クエリー)エラーまたは欠落しているデータベース:によって引き起こさ

は、あなたのスタックトレースに次の行を参照してください。構文エラー(コード1):、コンパイル中: tableADDRESS(ID整数主キーオートインクリメント県 テキスト、自治体テキスト、STREETテキスト、CITYテキスト、フラットテキスト、TRIBE テキスト、郊外テキストを作成 ( "tableADDRESSは" 近、TOWNテキスト、POSTテキスト))

関連する問題