can you please tell me how to load a html in web view in android.
I do the following step .i make www folder in asset folder in that I paste my html and js and css file.
please take a look on picture.Than i write xml code. and java code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
package com.example.test3;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
web = (WebView) findViewById(R.id.webView1);
web.getSettings().setLoadsImagesAutomatically(true);
web.getSettings().setJavaScriptEnabled(true);
web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
web.getSettings().setAppCacheEnabled(false);
web.getSettings().setSaveFormData(false);
web.loadUrl("file:///android_asset/www/parallel.html");
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
ERROR
04-13 05:36:37.726: E/AndroidRuntime(868): FATAL EXCEPTION: main
04-13 05:36:37.726: E/AndroidRuntime(868): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test3/com.example.test3.MainActivity}: java.lang.NullPointerException
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.os.Looper.loop(Looper.java:137)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-13 05:36:37.726: E/AndroidRuntime(868): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 05:36:37.726: E/AndroidRuntime(868): at java.lang.reflect.Method.invoke(Method.java:511)
04-13 05:36:37.726: E/AndroidRuntime(868): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-13 05:36:37.726: E/AndroidRuntime(868): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-13 05:36:37.726: E/AndroidRuntime(868): at dalvik.system.NativeStart.main(Native Method)
04-13 05:36:37.726: E/AndroidRuntime(868): Caused by: java.lang.NullPointerException
04-13 05:36:37.726: E/AndroidRuntime(868): at com.example.test3.MainActivity.onCreate(MainActivity.java:19)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.Activity.performCreate(Activity.java:5104)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-13 05:36:37.726: E/AndroidRuntime(868): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-13 05:36:37.726: E/AndroidRuntime(868): ... 11 more