Hi,
I have a problem with my Game App: On my device all is working fine, but at other Devices it crashes at the start. I get these errors: (Pic 1/2 sry for bad pics :S)
My Database Handler looks as following:
I am sorry for so much code and i hOpe someone can help me.
Mfg
Lolxdfly
I have a problem with my Game App: On my device all is working fine, but at other Devices it crashes at the start. I get these errors: (Pic 1/2 sry for bad pics :S)
My Database Handler looks as following:
Code:
//...
public class SQLHandler extends SQLiteOpenHelper
{
// Database Version
private static final int DATABASE_VERSION = 6;
// Database Name
private static final String DATABASE_NAME = "MRPIGDB";
public SQLHandler(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
// SQL statement to create the table
String CREATE_MRPIG_TABLE = "CREATE TABLE IF NOT EXISTS mrpig ( " +
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"points INTEGER )"; // +
//"name" DATA-TYPE )";
// create table
db.execSQL(CREATE_MRPIG_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS mrpig");
// create fresh table
this.onCreate(db);
initDB(0);
}
//table name ***
private static final String TABLE_MRPIG = "mrpig";
//Table Columns names ***
private static final String KEY_ID = "id";
private static final String KEY_POINTS = "points";
//private static final String KEY_ = "";
private static final String[] COLUMNS = {KEY_ID, KEY_POINTS /*,KEY_*/};
public void initDB(int points)
{
// 1. get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// 2. create ContentValues to add key "column"/value
ContentValues values = new ContentValues();
values.put(KEY_POINTS, points);
// 3. insert
db.insert(TABLE_MRPIG, // table
null, //nullColumnHack
values); // key/value -> keys = column names/ values = column values
// 4. close
db.close();
}
public int getpoints() //called at start to draw the highstore at screen
{
// 1. get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();
// 2. build query
Cursor cursor =
db.query(TABLE_MRPIG, // a. table
COLUMNS, // b. column names
" id = ?", // c. selections
new String[] { String.valueOf(1) }, // d. selections args
null, // e. group by
null, // f. having
null, // g. order by
null); // h. limit
// 3. if we got results get the first one
if (cursor != null)
cursor.moveToFirst();
// 4. get points !!!!!!!!!!ERROR HERE!!!!!!!
int points = (Integer.parseInt(cursor.getString(1)));
// 5. return points
return points;
}
public int updatePoints(int points)
{
// 1. get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// 2. create ContentValues to add key "column"/value
ContentValues values = new ContentValues();
values.put(KEY_POINTS, points);
// 3. updating row
int i = db.update(TABLE_MRPIG, //table
values, // column/value
KEY_ID + " = ?", // selections
new String[] { String.valueOf(1) }); //selection args
// 4. close
db.close();
return i;
}
}
I am sorry for so much code and i hOpe someone can help me.
Mfg
Lolxdfly
Attachments
Last edited: