Reputation: 143
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!
Upvotes: 3
Views: 12826
Reputation: 1007544
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.
Upvotes: 19