3

I've read many descriptions on how to make this work, but it doesn't in my emulator, which is really frustrating. Should be piece of cake!

I made a supersimple html-file:

 <html>

    <head>
<h1> Hello </h1>

    </head>

    <body>
    </body>


</html>

And then I use this java code to implement it:

    package com.path.path;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;



public class hello extends Activity {

WebView webView;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.hello);



     String url =  "file:///assets/hello.html";
    webView = (WebView) this.findViewById(R.id.char_view);
    webView.loadUrl(url);


}

}

When I load this page in the emulator it says the page is not available. What am I missing??

Thanks!

1 Answer 1

19

Change file:///assets/hello.html to file:///android_asset/hello.html. This assumes that your HTML file is located at assets/hello.html in your project.

Also, move your <h1> element into the <body>, so that it will actually work.

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

2 Comments

It was as easy as that, been stuck with this silly issue all day! Thank you CommonsWare, I would vote up your Answer if I had those 15 rep..
David you don't have to up vote, this should be selected as the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.