Creating an Ionic 5 app with Capacitor, I'm running into this problem where it seems that capacitor.config.json is not being loaded.
This problem came after I've installed #codetrix-studio/capacitor-google-auth, before the project was running on android fine.
{
"appId": "com.luyou.clauncher",
"appName": "c-launchpad",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
},
"GoogleAuth": {
"scopes": [
"profile",
"email"
],
"serverClientId": "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", // On my project I'm using the real server client id
"forceCodeForRefreshToken": true
}
}
}
On the android studio the build goes okay but when you try to open the app, it does crash with the following:
D/Capacitor: Starting BridgeActivity
E/Capacitor: Unable to load capacitor.config.json. Run npx cap copy first
java.io.FileNotFoundException: capacitor.config.json
at android.content.res.AssetManager.nativeOpenAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:874)
at android.content.res.AssetManager.open(AssetManager.java:851)
at com.getcapacitor.FileUtils.readFile(FileUtils.java:148)
at com.getcapacitor.CapConfig.loadConfig(CapConfig.java:121)
at com.getcapacitor.CapConfig.loadDefault(CapConfig.java:85)
at com.getcapacitor.Bridge.<init>(Bridge.java:152)
at com.getcapacitor.Bridge$Builder.create(Bridge.java:1160)
at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:73)
at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:54)
at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:37)
at com.luyou.clauncher.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
D/Capacitor: Registering plugin: WebView
D/Capacitor: Registering plugin: AdMob
D/Capacitor: Registering plugin: GoogleAuth
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.luyou.clauncher, PID: 11477
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luyou.clauncher/com.luyou.clauncher.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.load(GoogleAuth.java:47)
at com.getcapacitor.PluginHandle.load(PluginHandle.java:95)
at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:59)
at com.getcapacitor.Bridge.registerPlugin(Bridge.java:464)
at com.getcapacitor.Bridge.registerAllPlugins(Bridge.java:419)
at com.getcapacitor.Bridge.<init>(Bridge.java:164)
at com.getcapacitor.Bridge$Builder.create(Bridge.java:1160)
at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:73)
at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:54)
at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:37)
at com.luyou.clauncher.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 11477 SIG: 9
capacitor.config.json is already on the root path of the project and doing npx cap copy or npx cap sync doesn't solve this problem, but actually is copying the www files. For some reason, the capacitor config simply is just not being copied.
Seems like Capacitor alpha versions are broken, so gonig back to Capacitor 2.4.7 fixes the problem. The capacitor.config.json is loading correctly and the native plugins are loading fine.
awesome, thanks #Adrian Legaspi.
Downgrading to capacitor 2.4.7 solved it for me.
This is what my package.json looks like:
"dependencies": {
...
"#capacitor/android": "^2.4.2",
"#capacitor/core": "2.4.7",
..
},
"devDependencies": {
...
"#capacitor/cli": "2.4.2",
...
}
Related
I have this one line under MainActivity.kt file, no syntax errors and gradle is completely building the app, but when I open it in Emulator (Android 11) it closes instantly with message "App stopped working"
on messing around this is the one line causing it
var Thelist = findViewById<ImageButton>(/*Correct ImageButton D*/)
The logs of Emulator show
Process: com.cobalt.MyApp, PID: 5052
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cobalt.MyApp/com.cobalt.MyApp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:173)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
at android.content.Context.obtainStyledAttributes(Context.java:744)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:852)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:819)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:640)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:261)
at com.cobalt.MyApp.MainActivity.<init>(MainActivity.kt:76)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
The app refused to open itself despite compiling successfully
Upgraded Android API Level to 31 and then had to update Unity FB sdk (updated FB SDK to fix this).
In the new updated SDK when we try to facebook login we the game crashes and this is the device log
2022-10-18 12:36:22.428 2310-2310/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.risingtidegames.blackdiamondslots.beta, PID: 2310
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/activity/result/ActivityResultRegistryOwner;
at com.facebook.login.LoginManager.logIn(LoginManager.java:838)
at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:572)
at com.facebook.unity.FBLogin.login(FBLogin.java:163)
at com.facebook.unity.FBLogin.loginWithReadPermissions(FBLogin.java:44)
at com.facebook.unity.FBUnityLoginActivity.onCreate(FBUnityLoginActivity.java:40)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4009)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.ClassNotFoundException: androidx.activity.result.ActivityResultRegistryOwner
at com.facebook.login.LoginManager.logIn(LoginManager.java:838)
at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:572)
at com.facebook.unity.FBLogin.login(FBLogin.java:163)
at com.facebook.unity.FBLogin.loginWithReadPermissions(FBLogin.java:44)
at com.facebook.unity.FBUnityLoginActivity.onCreate(FBUnityLoginActivity.java:40)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4009)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)```
Morning everyone,
Whilst trying to integrate Branch.io and Capacitor following their guide (https://help.branch.io/developers-hub/docs/capacitor)
I am receiving this error:
2022-03-30 09:58:21.551 8066-8066/com.aks.cardTwist E/m.aks.cardTwis: Invalid ID 0x00000000.
2022-03-30 09:58:21.554 8066-8066/com.aks.cardTwist D/AndroidRuntime: Shutting down VM
2022-03-30 09:58:21.557 8066-8066/com.aks.cardTwist E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.aks.cardTwist, PID: 8066
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aks.cardTwist/com.aks.cardTwister.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.getcapacitor.BridgeActivity.onCreate(BridgeActivity.java:28)
at com.aks.cardTwister.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I have noticed line 6 they tell you to add within AndroidManifest.xml is the cause of the issue
Any advice would be greatly appreciated
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 1 year ago.
at first when I started the app the error sad "unable to delete directory" so i delete that file. The virtual devices started but the app keep stopping and I can't find why.
Process: com.example.library, PID: 10926
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.library/com.example.library.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.library.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
this is the error when i start the app
A Button in the MainActivity line 20 is not be inited.
you should init the button by :
Button btn = (Button)findViewById(R.id.btn);
Before use btn.serOnClickListener...
My app is simple, I want to load the existing '/storage/emulated/0/Download/my_database' as readonly in the android app.
But when I tried using
SQLiteDatabase.openDatabase("/storage/emulated/0/Download/my_database", null, SQLiteDatabase.OPEN_READONLY);
It fails with following error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sagar.towerlocator, PID: 7660
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sagar.towerlocator/com.sagar.towerlocator.MainActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: Cannot open database '/storage/emulated/0/Download/my_database': File /storage/self/primary/Download/db_verizon is not readable
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: Cannot open database '/storage/emulated/0/Download/my_database': File /storage/emulated/0/Download/my_database is not readable
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:252)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:205)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:505)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:198)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:918)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:736)
at com.sagar.towerlocator.MainActivity.loadDatabase(MainActivity.java:58)
at com.sagar.towerlocator.MainActivity.onCreate(MainActivity.java:53)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:224)
Note: Everything seems working if I store database under '/data/data/<package>/databases/' directory, but my requirement is to work from any other location
Please advice me.
There can be many reasons why you are getting SQLiteCantOpenDatabaseException.
I believe you can check if the file is corrupted or not, by starting adb shell and then by running:
sqlite3 <your-db-name>.db
Also, since you are reading from external storage, have you declared read permission for external storage in Android Manifest.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Ref: READ_EXTERNAL_STORAGE