i want to create a SQLLite Database with "openOrCreateDatabase". The problem is, that i get an error while creating a new table.
11-11 12:36:39.865: E/AndroidRuntime(1520): java.lang.IllegalStateException:
database not open
This is my code:
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')");
... ..
I added 2 lines in the manifest:
< permission-group android:name="android.permission-group.STORAGE">
< uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Whats wrong ?
Thanks a lot !
You shouldn't be accessing your database like this. And also you don't need storage permissions for /data/data, that's for sdcard. What you should be doing is using SQLiteOpenHelper to manage your db. Here's a tutorial to get you started
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.