访问 Android 的存储时出错:java.net.MalformedURLException:无协议:
Error when accessing Android`s storage: java.net.MalformedURLException: no protocol:
我在尝试访问应用程序的存储空间时遇到此错误(尝试了私有和共享)。我尝试添加 file://
但它似乎没有帮助。
String path = getFilesDir().getAbsolutePath() + File.separator + BUNDLE_NAME; // /data/user/0/com.package.vpn/files/rn.bundle
File file2 = new File(path);
if (file2 != null && file2.exists()) {
try {
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setCurrentActivity(currentActivity)
.setJSBundleFile(path) // accessing internal storage
.addPackages(packages)
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
} catch (Exception e2) { }
错误:
2022-02-24 13:35:39.466 16294-16799/com.package.vpn E/unknown:ReactNative: Exception in native call
java.net.MalformedURLException: no protocol:
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:498)
at java.net.URL.<init>(URL.java:447)
at com.facebook.react.devsupport.DevSupportManagerBase.resetCurrentContext(DevSupportManagerBase.java:707)
at com.facebook.react.devsupport.DevSupportManagerBase.onNewReactContextCreated(DevSupportManagerBase.java:617)
at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1126)
at com.facebook.react.ReactInstanceManager.access00(ReactInstanceManager.java:136)
at com.facebook.react.ReactInstanceManager.run(ReactInstanceManager.java:1086)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:237)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:919)
文件确实按预期加载(没有添加 'file://'),但错误不断发生。
您缺少 setJSMainModulePath("index")
我在尝试访问应用程序的存储空间时遇到此错误(尝试了私有和共享)。我尝试添加 file://
但它似乎没有帮助。
String path = getFilesDir().getAbsolutePath() + File.separator + BUNDLE_NAME; // /data/user/0/com.package.vpn/files/rn.bundle
File file2 = new File(path);
if (file2 != null && file2.exists()) {
try {
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setCurrentActivity(currentActivity)
.setJSBundleFile(path) // accessing internal storage
.addPackages(packages)
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
} catch (Exception e2) { }
错误:
2022-02-24 13:35:39.466 16294-16799/com.package.vpn E/unknown:ReactNative: Exception in native call
java.net.MalformedURLException: no protocol:
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:498)
at java.net.URL.<init>(URL.java:447)
at com.facebook.react.devsupport.DevSupportManagerBase.resetCurrentContext(DevSupportManagerBase.java:707)
at com.facebook.react.devsupport.DevSupportManagerBase.onNewReactContextCreated(DevSupportManagerBase.java:617)
at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1126)
at com.facebook.react.ReactInstanceManager.access00(ReactInstanceManager.java:136)
at com.facebook.react.ReactInstanceManager.run(ReactInstanceManager.java:1086)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:237)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:919)
文件确实按预期加载(没有添加 'file://'),但错误不断发生。
您缺少 setJSMainModulePath("index")