Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

android - Problems loading html asset into webview

I am having difficulty in loading a html file from my project assets folder into a webview. I have looked at dozens of tutorials and solutions but none seem to work for me.

In my project's assets folder I have two simple html files. index.html and faq.html (The plan is to utilise this structure for my help documentation)

My code:

    WebView wv = (WebView)findViewById(R.id.webview1);
    wv.setWebViewClient(new WebViewClient() {  
          @Override  
          public boolean shouldOverrideUrlLoading(WebView view, String url)  
          {  
            view.loadUrl(url);
            return true;
          }  
        });         
    wv.loadUrl("file:///android_asset/index.html");    

The webview displays the following:

Web Page Not Available

The Web Page at file:///android_asset/index.html could not be loaded as:

The requested file was not found. index.html

From everything I have read what I have here should work, but it does not.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

your usage is right, so if has this problem, you need check the index.html file existed or not carefully, also you can clean the project, and rebuild it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...