I have one minor doubt for which I was not able to get a satisfying answer. Here's the scenario:
I get a NPE during onCreate method of the OpenHelper class when I increase the number of tables in an already existing database , but when I run the same app after clearing the emulator data everything seems to run miraculously fine....
I have no idea why this happens, any explanation would be helpful....
public static final String DATABASE_NAME = "MONEY_DATABASE";
public static final String TABLE_NAME = "MONEY_TABLE";
public static final String TABLE_FIELDS = "FIELD_TABLE";
public static final int DATABASE_VERSION = 4;
public static final String KEY_ID = "_id";
public static final String KEY_AMOUNT = "amount";
public static final String KEY_DATE = "date_int";
public static final String KEY_TYPE_ID = "type_id";
public static final String KEY_TYPE = "type";
public static final String KEY_TITLE = "field_title";
Context localContext;
public HelperMethods (Context c)
{
Log.d("dev","HelperMethods object created");
this.localContext = c;
localopenhelper = new OpenHelper(localContext);
if(localContext == null)
{
Log.d("dev","localContext is null");
}
}
public SQLiteDatabase database ;
class OpenHelper extends SQLiteOpenHelper
{
// CREATE TABLE MONEY_TABLE ( _id INTEGER PRIMARY KEY AUTOINCREMENT, amount DOUBLE);
private String query = "CREATE TABLE " + TABLE_NAME + " ( " + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_AMOUNT + " DOUBLE, " + KEY_DATE + " DOUBLE);";
private String query1 = "CREATE TABLE " + TABLE_FIELDS + " ( " + KEY_TYPE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_TYPE + " TEXT NOT NULL, " + KEY_TITLE + " TEXT NOT NULL);";
Context helperContext;
public OpenHelper(Context context)
{
super(context, DATABASE_NAME, null , DATABASE_VERSION);
this.helperContext = context;
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(query);
db.execSQL(query1);
}
0 comments:
Post a Comment