Skip to main content

public class MyOpenHelper extends SQLiteOpenHelper {

public class MyOpenHelper extends SQLiteOpenHelper {

    public MyOpenHelper(Context context) {
        super(context, "NameCommentDB", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        
        db.execSQL("create table person(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");
        
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

}

*エラー時コード

public class MyOpenHelper extends SQLiteOpenHelper {

public class MyOpenHelper extends SQLiteOpenHelper {

    public MyOpenHelper(Context context) {
        super(context, "NameCommentDB", null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table person(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");

        db.execSQL("create table oasis(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.building_event);
MyOpenHelper helper = new MyOpenHelper(this);

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.building_event);
        MyOpenHelper helper = new MyOpenHelper(this);


     ***   final SQLiteDatabase db = helper.getReadableDatabase(); ←

エラーメッセージ*

E/SQLiteLog: (1) near ")": syntax error

E/AndroidRuntime: FATAL EXCEPTION: main

E/SQLiteLog: (1) near ")": syntax error

E/AndroidRuntime: FATAL EXCEPTION: main

public class MyOpenHelper extends SQLiteOpenHelper {

public MyOpenHelper(Context context) {
    super(context, "NameCommentDB", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    
    db.execSQL("create table person(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");
    
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

*エラー時コード

public class MyOpenHelper extends SQLiteOpenHelper {

public MyOpenHelper(Context context) {
    super(context, "NameCommentDB", null, 2);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table person(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");

    db.execSQL("create table oasis(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.building_event);
MyOpenHelper helper = new MyOpenHelper(this);

 ***   final SQLiteDatabase db = helper.getReadableDatabase(); ←

エラーメッセージ*

E/SQLiteLog: (1) near ")": syntax error

E/AndroidRuntime: FATAL EXCEPTION: main

public class MyOpenHelper extends SQLiteOpenHelper {

    public MyOpenHelper(Context context) {
        super(context, "NameCommentDB", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        
        db.execSQL("create table person(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");
        
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

*エラー時コード

public class MyOpenHelper extends SQLiteOpenHelper {

    public MyOpenHelper(Context context) {
        super(context, "NameCommentDB", null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table person(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");

        db.execSQL("create table oasis(" +
                "name text not null," +
                "comment text," +
                "time text," +
                ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.building_event);
        MyOpenHelper helper = new MyOpenHelper(this);


     ***   final SQLiteDatabase db = helper.getReadableDatabase(); ←

エラーメッセージ*

E/SQLiteLog: (1) near ")": syntax error

E/AndroidRuntime: FATAL EXCEPTION: main
ソース リンク
Fuya
  • 21
  • 3

AndroidでのSQlite使用時に新規でテーブルを追加した際のエラー

色々なサイトを参考にさせて頂きつつSQliteを用いてデータベース構築を試しています。
一度テーブルを作成してデータベースにデータを入力、データベースから読み込みまで出来たのですが、新規にテーブルを追加するとアプリを削除してもコードを削除してもエラーが発生するようになりました。よろしければご教授お願いいたします。

*成功時コード

public class MyOpenHelper extends SQLiteOpenHelper {

public MyOpenHelper(Context context) {
    super(context, "NameCommentDB", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    
    db.execSQL("create table person(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");
    
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

*エラー時コード

public class MyOpenHelper extends SQLiteOpenHelper {

public MyOpenHelper(Context context) {
    super(context, "NameCommentDB", null, 2);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table person(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");

    db.execSQL("create table oasis(" +
            "name text not null," +
            "comment text," +
            "time text," +
            ");");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

**他クラスエラーメッセージ箇所

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.building_event);
MyOpenHelper helper = new MyOpenHelper(this);

 ***   final SQLiteDatabase db = helper.getReadableDatabase(); ←

エラーメッセージ*

E/SQLiteLog: (1) near ")": syntax error

E/AndroidRuntime: FATAL EXCEPTION: main