Ken Gordon
Newbie
You would tell me if I was crazy right?
I started a project with an sqlite database, made some really good progress, but when I went to build it out, the database was not created and it crashed after pushing one of the buttons. So I started over and didn't copy anything, but typed it out. The build still didn't work. so I stripped it down to two classes, the database helper and the main(blank) activity. Still the database is not getting created. Please save my sanity and my hair.
and
Thanks for the help!
I started a project with an sqlite database, made some really good progress, but when I went to build it out, the database was not created and it crashed after pushing one of the buttons. So I started over and didn't copy anything, but typed it out. The build still didn't work. so I stripped it down to two classes, the database helper and the main(blank) activity. Still the database is not getting created. Please save my sanity and my hair.
Java:
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper
{
public static final String DATABASE_NAME="Tracker.db";
public static final String ONE_TABLE="TableOne";
public static final String COL_ONE="ColOne";
public static final String COL_TWO="ColTwo";
public static final String TABLE_TWO="TableTwo";
public static final String COL_THREE="ColThree";
public static final String TABLE_THREE="TableThree";
public static final String COL_FOUR="ColFour";
public static final String TABLE_FOUR="Four";
public static final String COL_FOUR_DATE="FourDate";
public static final String COL_FOUR_LOCATION="FourLocation";
public static final String COL_FOUR_INTENSITY="FourIntensity";
public static final String COL_FOUR_KIND="FourKind";
public static final String COL_FOUR_SPAN="FourSpan";
public DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db=this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE "+TABLE_ONE +" (ColOne TEXT, ColTwo TEXT)");
db.execSQL("CREATE TABLE "+TABLE_TWO +" (ColThree TEXT)");
db.execSQL("CREATE TABLE "+TABLE_THREE +" (ColFour TEXT, ColFive TEXT)");
db.execSQL("CREATE TABLE "+TABLE_FOUR +" (FourDate TEXT, FourLocation TEXT, FourIntensity TEXT, FourKind TEXT, FourSpan TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("DROP TABLE If Exists "+TABLE_ONE);
db.execSQL("DROP TABLE If Exists "+TABLE_TWO);
db.execSQL("DROP TABLE if Exists "+TABLE_THREE);
db.execSQL("DROP TABLE If Exists "+TABLE_FOUR);
onCreate(db);
}
}
and
Java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
DatabaseHelper DB;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DB=new DatabaseHelper(this);
}
}
Thanks for the help!