I have this MainActivity, that calls a class that generates a database.
public class MainActivity extends Activity {
PlayerDataSource pds;
ArrayList<Player>listOfPlayer;
PlayerAdapter adapter;
ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
listview=(ListView) findViewById(R.id.allPlayers);
pds=new PlayerDataSource(this);
pds.open();
}
}
class PlayerDataSource:
public class PlayerDataSource {
Context context;
PlayerOpenHelper helper;
SQLiteDatabase database;
public PlayerDataSource(Context context)
{
this.context=context;
helper=new PlayerOpenHelper(context);
}
public void open()
{
database=helper.getWritableDatabase();
Log.i("data", "Database connection open");
}
public void close()
{
helper.close();
Log.i("data", "Database connection close");
}
}
here is the class PlayerOpenHelper that generates a database:
public class PlayerOpenHelper extends SQLiteOpenHelper {
public static final String DATABASENAME="player.db";
public static final String TABLE_PLAYER="tblplayer";
public static final int DATABASEVERSION=1;
public static final String COLUMN_ID="id";
public static final String COLUMN_NAME="name";
public static final String COLUMN_DATE="date";
public static final String COLUMN_SCORE="score";
public static final String COLUMN_GAME="game";
private static final String CREATE_TABLE_PLAYER="CREATE TABLE IF NOT EXISTS " +
TABLE_PLAYER + "(" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_NAME + " VARCHAR," + COLUMN_DATE + " VARCHAR,"
+ COLUMN_SCORE +" INTEGER," + COLUMN_GAME + " VARCHAR " + ");";
SQLiteDatabase database;
public PlayerOpenHelper(Context context) {
super(context, DATABASENAME, null, DATABASEVERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_PLAYER);
Log.i("data", "Table player has been just created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_PLAYER);
onCreate(db);
}
The problem is that when i try to do something with the database, to insert to it or to take data it makes an error that says that no such table:tblplayer