10

I am trying to load the contents of a html file in a webview in android. However, it gives me the "Webpage not available error". If I try websites such as google or yahoo, they work.

The html file are under src > main > assests > index.html

Can someone help me with this issue. Thank You.

Following is my code :

setContentView(R.layout.activity_main);

WebView mWebView;
mWebView = (WebView) findViewById(R.id.activity_main_webview);

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

mWebView.loadUrl("file:///android_asset/index.html");

XML File :

<WebView
    android:id="@+id/activity_main_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
1
  • 3
    I hope your asset folder is not really named assests. Commented Feb 4, 2014 at 16:24

1 Answer 1

9

The html file should be placed in the assets folder (note the spelling), which will belong in the root directory of your project.

So move

src/main/assests/index.html

to

assets/index.html

In an Android Studio project use this folder:

/app/src/main/assets/index.html
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.