加载html文件时找不到文件错误

时间:2017-10-13 10:04:22

标签: android html webview

//这是从html文件加载的地方

    progres = ProgressDialog.show(activity, "Please wait!", "Loading...");

          web.setWebViewClient(new WebViewClient() {
          public void onReceivedError(WebView view, int errorCode, String 
          description, String failingUrl) {
                Toast.makeText(activity, description, 
                Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progres.dismiss();
            }
        });

        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("file:///android_assets/sample.html");
      }
   }

assets file location

2 个答案:

答案 0 :(得分:1)

web.loadUrl("file:///android_asset/sample.html");

android_asset not android_assets

答案 1 :(得分:0)

试试这个

    web.loadUrl(getAssets().open("sample.html"));