0

我正在尝试将我的游戏配置保存在数据库中,我在此页面中使用了一个教程:page。我将这个类称为 configuracion:

public class Configuraciones extends SQLiteOpenHelper {

static final String table_name = "configuraciones";
static final String cod_config = "id";
static final String nom_config = "nombre";
static final String val_config = "valor";

public Configuraciones(Context context) {
    super(context, "bdd_cuarenta", null, 1);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_TABLE = "CREATE TABLE " + table_name + "("
            + cod_config + " INTEGER PRIMARY KEY," + nom_config + " TEXT,"
            + val_config + " TEXT" + ");";
    // ESTABLISH NEW DATABASE TABLES IF THEY DON'T ALREADY EXIST IN THE DATABASE
    db.execSQL(CREATE_TABLE);

    //Ingresa las configuraciones por primera vez
    ingresaTablas(db);
}

@Override
public void onUpgrade(SQLiteDatabase db, int vieja, int nueva) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS " + table_name);
    onCreate(db);
}

public String consultaConfiguracion(String nombre){
    SQLiteDatabase myDB = getReadableDatabase();
    String[] mySearch = new String[]{nombre};
    Cursor myCursor = myDB.rawQuery("SELECT "+ val_config +" FROM "+ table_name +" WHERE "+ nom_config +"='?'",mySearch);
    myCursor.moveToFirst();
    int index = myCursor.getColumnIndex(val_config);
    String myAnswer = myCursor.getString(index);
    myCursor.close();
    return myAnswer;
}

public int actualizaConfig(String nombre, String nuevaConfig)
{         
        SQLiteDatabase myDB = getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(val_config, nuevaConfig);
        int numRowsAffected = myDB.update(table_name, cv, nom_config+"='?'", new String []{String.valueOf(nombre)});
        return numRowsAffected;
}

但是当我调用其中一种方法时,例如actualizaConfig,我得到了错误:

java.lang.IllegalStateException:递归调用 getDatabase

在我的游戏活动中,我通常调用这样的对象:

private BoundCamera camera;
private Configuraciones configs;

@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) 
{
    return new LimitedFPSEngine(pEngineOptions, 60);
}

public EngineOptions onCreateEngineOptions()
{
    camera = new BoundCamera(0, 0, 800, 480);
    configs = new Configuraciones(this);
    EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.camera);
    engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
    engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    return engineOptions;
}

在 GameScene 中,我调用这样的方法:

resourcesManager.config.actualizaConfig("diseno_carta", "9");

我不知道为什么会出现问题... :(

4

0 回答 0