我正在 android 中构建一个数据库类,它从 getIntent().getStringExtra(name) 函数收集字符串非静态数据。我将这个值放入一个简单的字符串变量(非静态)中。
当我尝试在静态字符串中使用它时,出现错误 - “无法对非静态字段进行静态引用”。
我该如何解决这个问题?这是我的代码:
package ent.com;
import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
public class SetSql extends Activity{
String saveExtra = getIntent().getStringExtra("save");
public static final String KEY_ROWID = "_id";
public static final String KEY_SAVE = "save_name";
public static final String KEY_STADUIM = "stadium_size";
public static final String KEY_FINANCE = "total_money";
public static final String KEY_PLAYERS = "players";
private static String DATABASE_NAME = "save" + saveExtra;
private static final String DATABASE_TABLE = "save_data";
private static final int DATABASE_VERSION = 1;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
}
}
谢谢你的帮助 :)