xz ayt xz ayt - 23 days ago 6
Android Question

SQLite android does not create the DB table (called from fragment)

I am trying to parse A JSON from the server and the parsed objects to the SQLite on android.

SQLHandler.java

public class SQLiteHandler extends SQLiteOpenHelper {

private static final String TAG = SQLiteHandler.class.getSimpleName();


public SQLiteHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}



// Create Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USER + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_EMAIL + " TEXT UNIQUE," + KEY_UID + " TEXT,"
+ KEY_CREATED_AT + " TEXT" + ")";



String CREATE_ZONE_TABLE = "CREATE TABLE " + TABLE_ZONES + "("
+ KEY_ZONE_ID + " INTEGER," + KEY_ZONE_NAME + " TEXT" + ")";


db.execSQL(CREATE_ZONE_TABLE);
db.execSQL(CREATE_LOGIN_TABLE);
}


It should automatically create the zones table but it does not. When running the app I have the error that zones table does not exist. I am calling the SQLHandler from my fragment activity from the onCreateView. Why it does not create the table? (I've taken the code from my another app where the table is created after I call the SQLhandler from the onCreate method)

SendDataFragment.java:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

db = new SQLiteHandler(getActivity().getApplicationContext());
// db.deleteZones();
ZonesArray = new ArrayList<>();
new GetZones().execute();
FrameLayout rootView = (FrameLayout) inflater.inflate(R.layout.fragment_send, container, false);
...

Answer

A small advice to Uninstall the application and run it again.