Mayank Garachh Mayank Garachh - 5 months ago 10
Android Question

can`t webview load html page from assets folder

in my app not load html page from assets folder and not error are occur and screen are display as blank

webView = (WebView) findViewById(R.id.htmlviewer);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/index.html");
setContentView(R.layout.htmldesplay);

Answer

Try to add setContentView before getting WebView

Replace your code with this

setContentView(R.layout.htmldesplay); 
webView = (WebView) findViewById(R.id.htmlviewer);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/index.html");

instead of

webView = (WebView) findViewById(R.id.htmlviewer);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/index.html");
setContentView(R.layout.htmldesplay);