I have a webview in my app that has to load an image, it loads it fine however it takes a few seconds for it to display. So what i need to do is to display a progress dialog to inform the user that the page is loading. (this image is loading from assets folder and not from the web) So this is my code sofar but crashes when i try to run that activity.

public MapsFragment(){}
ProgressDialog progress;
WebView myWebView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_maps, container, false);

    WebView webview = (WebView)rootView.findViewById(R.id.webView2);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setUseWideViewPort(false);
    webview.loadUrl("file:///android_asset/index1.html");

    webview.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            progress.show();
            view.loadUrl(url);
            return true;                
        }
        @Override
        public void onPageFinished(WebView view, final String url) {
            progress.dismiss();
        }
    });

    return rootView;
 }
}

And then the error code for this is:

11-08 13:19:34.034: E/AndroidRuntime(20600): FATAL EXCEPTION: main
11-08 13:19:34.034: E/AndroidRuntime(20600): Process: com.test.testguide, PID: 20600
11-08 13:19:34.034: E/AndroidRuntime(20600): java.lang.NullPointerException
11-08 13:19:34.034: E/AndroidRuntime(20600):    at com.test.testguide.MapsFragment$1.onPageFinished(MapsFragment.java:42)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:449)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at com.android.org.chromium.android_webview.AwContentsClient$AwWebContentsObserver$1.run(AwContentsClient.java:73)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at android.os.Handler.handleCallback(Handler.java:733)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at android.os.Handler.dispatchMessage(Handler.java:95)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at    android.os.Looper.loop(Looper.java:136)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at android.app.ActivityThread.main(ActivityThread.java:5586)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at java.lang.reflect.Method.invokeNative(Native Method)
11-08 13:19:34.034: E/AndroidRuntime(20600):    at java.lang.reflect.Method.invoke(Method.java:515)

Please help, as i have googled so many questions regarding this and couldn't seem to find a solution.
Thank you!

EDIT

Ihave corrected the error by myWebView and changed back to webview, Thus resulting into a new error. Please see updated question

Related posts

Recent Viewed