2017-06-05 11 views
0

Android(API 25)でSQLiteデータベースを作成して使用しようとしています。 私はマニフェストに許可を与えます。私は多分データベースのパスに問題があると思う。しかし、私はこの問題を解決するためcan`t ...データベース口コードAndroid sqlExcetion opening db:許可が拒否されたJDBC

String db = "jdbc:sqlite:" + Environment.getDataDirectory().getAbsolutePath() + "/MyDatabase.db"; 
     Class.forName("org.sqlite.JDBC"); 

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

あります。しかし権限

06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err: java.sql.SQLException: opening db: '/data/MyDatabase.db': Permission denied 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.core.CoreConnection.open(CoreConnection.java:203) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:24) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.JDBC.createConnection(JDBC.java:114) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at org.sqlite.JDBC.connect(JDBC.java:88) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at java.sql.DriverManager.getConnection(DriverManager.java:569) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at java.sql.DriverManager.getConnection(DriverManager.java:237) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at com.example.user.app.DB.openDbConnection(DB.java:33) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at com.example.user.app.Helpers.isTableIsEmpty(Helpers.java:24) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at com.example.user.app.activity.BachelorITFCourses1.onCreate(BachelorITFCourses1.java:42) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at android.app.Activity.performCreate(Activity.java:6679) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:102) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.os.Looper.loop(Looper.java:154) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:6119) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at java.lang.reflect.Method.invoke(Native Method) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

P.S.に関するいくつかのエラーがあります私はdtabaseアクションのための特別なクラスのDBを持っています。

答えて

0

私は必要な権限を要求する必要があると思いますか?このようなもの?

if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.READ_CONTACTS) 
     != PackageManager.PERMISSION_GRANTED) { 

    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
      Manifest.permission.READ_CONTACTS)) { 

     // Show an explanation to the user *asynchronously* -- don't block 
     // this thread waiting for the user's response! After the user 
     // sees the explanation, try again to request the permission. 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.READ_CONTACTS}, 
       MY_PERMISSIONS_REQUEST_READ_CONTACTS); 

     // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an 
     // app-defined int constant. The callback method gets the 
     // result of the request. 
    } 
} 
関連する問題