• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help can't Create sqlite db on click button

Hello guys,

I tried to create database on click button and still not able to create.

- - - - - - - - - - - - - -- - - - - - -- - - - - - -- - - - - - -- - - - - - -- - - - - - -
super.onCreate(savedInstanceState);

SQLiteDatabase myDB= null;
String TableName = "contact";

myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ TableName + " (ID VARCHAR(10), Name VARCHAR(100));");
- - - - - - - - - - - - - -- - - - - - -- - - - - - -- - - - - - -- - - - - - -- - - - - - -
if I write code below at " super.onCreate(savedInstanceState); ". There is no error occur.

if I try to place those code under a function or method, the error occur


what should I have to do to fix the error?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones