0

Good afternoon,

I am trying to create a database for a monthly assessment form as part of my, it will be the second table of my application first being login details.

I followed the same format but am getting "NO SUCH TABLE" followed by my variable name.

I was hoping this issue had been seen before and how it could be eradicated.

3 Answers 3

1

Uninstall the old application on your phone completely and run your project again. This error is happening because the onCreate() method of the SQLiteOpenHelper derived class is called only once. For it to be called again, either you derive another custom class from SQLiteOpenHelper and define your second table there, or you uninstall the old APK and re-run the project from the IDE. When you run it again, both tables will be created.

Sign up to request clarification or add additional context in comments.

5 Comments

@Zygotelnit Hi and thanks for the rapid response. I am however still getting the error. I have updated the question above to reflect the error log showing but I have tried uninstalling the apk to device but unfortunately it does not seem to be creating the table
i will get back to you in a few minutes :)
Very kind @Zygotelnit :)
@Zygotelnit The error was in my DatabaseHelper.java which I did not post! In the public void onCreate(SQLiteDatabase _db) I did not state the new database was to be created! Thanks for your input!
You're welcome ... I believe you got to see first hand that when working with SQLite tables which are all defined in the same onCreate(), the old APK should be deleted when a new table is added.
0

Make database like this :

public class Data_Base extends SQLiteOpenHelper {
    public static final String dbname = "suri29";
    public static final Integer dbversion = 1;
    public static final String dbtable = "user";
    public static final String name = "username";
    public static final String column_id = "_id";

    public Data_Base(Context context) {
        super(context, dbname, null, dbversion);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("create table " + dbtable + " (" + column_id
                + " integer primary key autoincrement, username text not null)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVesion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("drop table if exists " + dbtable);
        onCreate(db);
    }

Comments

0

Without digging deeper into you code, I have some advices for you that going to make you avoid tons of mistakes:

1)Use SQLite Database Helper for creating, inserting, deleting you data from the database...Follow this tutorial

2)Rewriting your columns name in each query is a very bad practice. Initialize them at the beginning of your class as final static string and use this variable whenever you need it.

private final static String COL_COMMENTS = "COMMENTS";

3)Try and catch all your database transactions with logging to avoid crashes.

try{
  //Database transaction
 }
 catch(Exception e){
  e.printstacktrace();
 }

4)Uninstall the application and install it again after adding any new table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.