0

In my android app, I have used SQLite database in the initial versions. I need to create a new table now in the app. I have given create statement in onCreate() and onUpgrate(), but both are not wroking and I am getting the error:

android.database.sqlite.SQLiteException: no such table

I tried, try...catch() which is also not working. Please suggest me a solution.

3
  • 1
    Do you set the database version? As far as i know onUpgrade() calls if the old db version is less than newer db version Commented Sep 24, 2015 at 17:37
  • add some code. then only we can identify what is the error. Commented Sep 24, 2015 at 17:38
  • Thanks Madushan, setting new db version solved the issue. Commented Sep 25, 2015 at 8:25

2 Answers 2

0

By searching the error line you can find other same solved questions on stackoverflow.
take a look at: problem about sqlite database, no such table:

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

Comments

0

There might be a reason that your table is already created.... try a new test app with this code (worked for me)

make a Test app with only one button which create a table

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Button btn = (Button) findViewById(R.id.button1);
  btn.setOnClickListener(new View.OnClickListener(){
   @Override
   public void onClick(View v) {

   SQLiteDatabase objConnection=openOrCreateDatabase("database_name",MODE_PRIVATE,null);
objConnection.execSQL("Create Table IF NOT EXISTS table_name(id INTEGER primary Key AUTOINCREMENT, name Varchar(200))");
objConnection.close();
Toast.makeText(getApplicationContext(), "db created", Toast.LENGTH_SHORT).show();

}
});
} 

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.