1

I have a WebView and I want to store a webpage locally and open it on startup. But it's giving me the following error:

The Requested file was not found 123.html maybe this is because i have two "mWebView.loadUrl". I was unable to solve this problem because I'm new to Eclipse and Java, any help will be appreciated!

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Browser extends Activity {
    private WebView mWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browser);

        mWebView = (WebView) findViewById(R.id.webView1);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com");
        mWebView.setWebViewClient(new HelloWebViewClient());
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.loadUrl("file:///android_asset/123.html");
    }

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView webview, String url)
        {
            webview.loadUrl(url);
            return true;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
        {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
6
  • You have placed 123.html in your /assets/ directory? Commented Dec 12, 2013 at 14:26
  • its in the "assets" folder Commented Dec 12, 2013 at 14:34
  • Well, that is weird. It should work. Double check the filename and folder location, and try cleaning your project via Project/Clean. Also no need to load the google homepage first, remove that call. Commented Dec 12, 2013 at 14:54
  • i tripple checked it, i have also many other html files lying in the same folder , all are opening but not this one Commented Dec 12, 2013 at 14:56
  • Tried renaming it and seeing if you can access it via the new name? Commented Dec 12, 2013 at 14:56

2 Answers 2

1

You need a project sctructure like this:

src
  -- java files
rs
  -- resource files
assets
  123.html

your html file must be inside the folder assets.

more info in http://developer.android.com/tools/projects/index.html

Sign up to request clarification or add additional context in comments.

1 Comment

its in the "assets" folder
0

It seems like the location file:///android_asset/123.html does not exist.
Either put a real URL or check if this file really exists and on this location.

4 Comments

its in the "assets" folder
Try to debug it with: new File("file://android_assets").list() to see which files there is on this directory.. Or Try "file://assets/123.html" instead
DO YOU MEAN "asset" ??
"file://assets/123.html" OR "file:///asset/123.html"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.