0

Im trying to display my result in asynctask using webview but i got nullpointExc any help will be appreciated.

 @Override
    //Display my result via webview
    protected void onPostExecute(String result) { //where i get my result
        setContentView(R.layout.paynamics_layout);
        WebView myweb = (WebView) view.findViewById(R.id.paynamics_site);
        myweb.loadData(result, "text/html", null); // i got error here
        myweb.canGoBack();
        super.onPostExecute(result);

    }

Here is my error

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadData(java.lang.String, java.lang.String, java.lang.String)' on a null object reference
Shan
  • 301
  • 1
  • 3
  • 14

1 Answers1

1

There's no need to use setContentView. Use it only in onCreate();

You can try any one of the following methods -

  • Add WebView in your layout if its not already added!
  • Initialize the WebView variable in onCreate();
  • Keep the WebView's visibility as View.GONE;
  • loadData for WebView in OnPostExecute() & make it Visible by setVisibility(View.VISIBLE);

Or

  • Create another Activity which has a WebView in it;
  • Get the Data in onPostExecute();
  • Send the Data with Intent to the other Activity & display the same in the WebView.
Darshan
  • 4,020
  • 2
  • 18
  • 49