繁体   English   中英

无法打开资产 URL:file:///android_asset/test-wv/index.html

[英]Unable to open asset URL: file:///android_asset/test-wv/index.html

我在资产目录中加载 html,这是我的代码:

/home/roroco/Dropbox/jvs/ro-adr/app/src/main/java/ro/adr/test/TestWv.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_wv);
    WebView w = (WebView) findViewById(R.id.w);
    w.loadUrl("file:///android_asset/test-wv/index.html");
}

我确定这个 html 文件存在

/home/roroco/Dropbox/jvs/ro-adr/app/src/main/assets/test-wv/index.html

原因是“即时运行”,在我第一次启动webview时,assets/是空的,所以当我将index.html添加到assets/时,“即时运行”不会刷新assets/修改,解决方案:

  • 方式1:清除即时运行我必须:

    gradle :app:uninstallDebug

并重新运行调试

  • 方式2:禁用即时运行(在intellij idea>设置>即时运行>关闭“启用即时运行...”

如果你想在像我这样的资产中编写 webapp,禁用即时运行,如果没有修改 java 代码,“启用即时运行”和“禁用即时运行”将在我的代码中花费相同的构建时间

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM