Could Not Open Database In Android Studio

634
January 03, 2017, at 01:38 AM

I've created G class in-order to using database but in first steps I got this error :

   Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

Also in AndroidManifest.xml I added :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

This is my G class :

package com.example.n5110.database;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import java.io.File;
public class G extends Application {
    public static Context context;
    public static SQLiteDatabase database;
    public static final String DIR_SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
    public static final String DIR_DATABASE = DIR_SDCARD + "/database-test/";
    @Override
    public void onCreate() {
        super.onCreate();
        context = this.getApplicationContext();
        new File(DIR_DATABASE).mkdirs();
        database = SQLiteDatabase.openOrCreateDatabase(DIR_DATABASE + "/database.sqlite", null);
    }
}

Does anyone have an idea??

Answer 1

File dbFile = myContext.getDatabasePath(DB_NAME); return dbFile.exists();

Hope it helps

Rent Charter Buses Company
READ ALSO
send data to Observable in rx android

send data to Observable in rx android

I have observable like this:

366
How this draw pattern is explained?

How this draw pattern is explained?

I'm using onTouch method to acquire positions from ACTION_UP and ACTION_DOWN actionsWith this values I draw a red line from center to the position relative to the difference between the acquired positions

335
Creating a &#39;line connected&#39; recyclerview with cardviews

Creating a 'line connected' recyclerview with cardviews

how can I create the below layout where each record is a recyclerview recordI already have a recyclerview but how can i set the left icons to be connected by a line as shown below and what of the data on the right, is that a cardview?

376
Pie Chart with SharedPreferences

Pie Chart with SharedPreferences

I need to create a pie chart with data from SharedPreferencesThis is part of my code, but I can't understand why this isn't working:

415