我想用“openOrCreateDatabase”创建一个 SQLLite 数据库。问题是,我在创建新表时出错。
11-11 12:36:39.865: E/AndroidRuntime(1520): java.lang.IllegalStateException:
database not open
这是我的代码:
public class MainActivity extends Activity {
EditText playerName;
Button submitPlayer;
SQLiteDatabase myDB = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
playerName = (EditText)findViewById(R.id.playerName);
submitPlayer = (Button)findViewById(R.id.submitPlayer);
myDB = SQLiteDatabase.openOrCreateDatabase("/data/data/com.my.appname/mydb.db",null);
try{
myDB.execSQL("CREATE TABLE IF NOT EXISTS player (playername VARCHAR)");
myDB.execSQL("INSERT INTO player VALUES('test')");
...
..
我在清单中添加了 2 行:
<权限组android:name="android.permission-group.STORAGE">
< 使用权限 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
怎么了 ?
非常感谢 !