SQLiteOpenHelper和SQLiteDatabase无法解析符号

时间:2018-06-03 12:22:00

标签: android sqlite libgdx

我有一个libgdx游戏,我想用SQLite创建一个DataBase,但是当我创建数据库时,在beggining中会出现一些错误。这是代码:

import javax.naming.Context;

import borruey.catchemall.CatchEmAll;

public class DBAndroid extends DBHighScore{
    protected SQLiteOpenHelper db_connection;
    protected SQLiteDatabase stmt;

public DBAndroid(Context context) {
    db_connection = new AndroidDB(context, database_name, null, version);
    stmt=db_connection.getWritableDatabase();
}

public void execute(String sql){
    stmt.execSQL(sql);
}

public int executeUpdate(String sql){
    stmt.execSQL(sql);
    SQLiteStatement tmp = stmt.compileStatement("SELECT CHANGES()");
    return (int) tmp.simpleQueryForLong();
}

public Result query(String sql) {
    ResultAndroid result=new ResultAndroid(stmt.rawQuery(sql,null));
    return result;
}

class AndroidDB extends SQLiteOpenHelper {

    public AndroidDB(Context context, String name, CursorFactory factory,
                     int version) {
        super(context, name, factory, version);
    }

    public void onCreate(SQLiteDatabase db) {
        stmt=db;
        DatabaseAndroid.this.onCreate();
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        stmt=db;
        DatabaseAndroid.this.onUpgrade();
    }

}

public class ResultAndroid implements Result{
    Cursor cursor;

    public ResultAndroid(Cursor cursor) {
        this.cursor=cursor;
    }

    public boolean isEmpty() {
        return cursor.getCount()==0;
    }

    public int getColumnIndex(String name) {
        return cursor.getColumnIndex(name);
    }

    public String[] getColumnNames() {
        return cursor.getColumnNames();
    }

    public float getFloat(int columnIndex) {
        return cursor.getFloat(columnIndex);
    }

}

}

public class Main扩展AndroidApplication {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initialize(new CatchEmAll(new DatabaseAndroid(this.getBaseContext())), false);
}*/

}

DBHighScore课程:

public abstract class DBHighScore {

protected static String database_name="CatchEmAll";
protected static DBHighScore instance = null;
protected static int version=1;

public abstract void execute(String sql);

public abstract int executeUpdate(String sql);

public abstract Result query(String sql);

public void onCreate(){
    execute("CREATE TABLE 'highscores' ('_id' INTEGER PRIMARY KEY  NOT NULL , 'name' VARCHAR NOT NULL , 'score' INTEGER NOT NULL );");

    Result q=query("SELECT * FROM 'highscores'");
    if (!q.isEmpty()){
        q.moveToNext();
        System.out.println("Highscore of "+q.getString(q.getColumnIndex("name"))+": "+q.getString(q.getColumnIndex("score")));
    }
}

public void onUpgrade(){
    execute("DROP TABLE IF EXISTS 'highscores';");
    onCreate();
}

public interface Result{
    public boolean isEmpty();
    public boolean moveToNext();
    public int getColumnIndex(String name);
    public float getFloat(int columnIndex);
}

}

错误:

无法解析符号'SQLiteOpenHelper'和 无法解析符号'SQLiteDatabase'

有什么问题?

0 个答案:

没有答案