【问题标题】:Unable to open asset URL: file:///android_asset/test-wv/index.html无法打开资产 URL:file:///android_asset/test-wv/index.html
【发布时间】:2020-08-01 11:21:46
【问题描述】:

我在 assets 目录中加载 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

【问题讨论】:

  • 我不知道 HTML 必须在 /src/main/assets/index.html 中,但您必须将其称为“file:///android_asset/index.html

标签: android


【解决方案1】:

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

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

    gradle:app:uninstallDebug

然后重新运行调试

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 2017-10-24
    • 2021-06-03
    相关资源
    最近更新 更多