开发者

Why do I get a NullPointerException when I pass an url to the webview?

I get a NullPointerException when a url passed in webview in an activity (the url is passed from previous activity), but it shows NullPointerException when control goes on webview.loadurl(url). I checked that there is a value in a passed url but I still don't know why it gives an error?

This is Error:

06-07 15:13:43.689:ERROR/AndroidRuntime(1761): FATAL EXCEPTION: main 
06-07 15:13:43.689: ERROR/AndroidRuntime(1761): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopzilla.android.common/com.shopzilla.android.product.ProductStoreActivity}: java.lang.NullPointerException 
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
 06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.os.Looper.loop(Looper.java:123)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at java.lang.reflect.Method.invokeNative(Native Method) 
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at java.lang.reflect.Method.invoke(Method.java:507)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at dalvik.system.NativeStart.main(Native Method)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761): Caused by: java.lang.NullPointerException
06-0715:13:43.689: ERROR/AndroidRuntime(1761):     at com.shopzilla.android.product.ProductStoreActivity.onCreate(ProductStoreActivity.java:40)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-07 15:13:43.689: ERROR/AndroidRuntime(1761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

Code:

package com.shopzilla.android.product;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.shopzilla.android.common.R;

public class ProductStoreActivity extends Activity{

  ProgressDialog dialog;
  Dialog dialog1;
  int count=0;
  Bundle bundle;
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    dialog = ProgressDialog.show(this,"BIZRATE","Loading....");
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    setContentView(R.layout.storesitenew);
    bundle = getIntent().getExtras();
    //getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
    //Bundle bundle = getIntent().getExtras();
    WebView web = (WebView)findViewById(R.id.web_storesite);
    //MyWebViewClient web1 = new MyWebViewClient();
    //web1.shouldOverrideUrlLoading(web, ProductComparisonActivity.store_url);
    //web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl(bundle.getString("url"));
    web.setWebViewClient(new MyWebViewClient());


    Button btn_back = (Button)findViewById(R.id.btn_back_bizrate);
    btn_back.setOnClickListener(new View.OnClickListener() {

      public void onClick(View arg0) {
        finish();   
      }
    });

    Button btn_globe = (Button)findViewById(R.id.btn_store_globe);
    btn_globe.setOnClickListener(new View.OnClickListener() {

      public void onClick(View arg0) {
        Intent browserIntent =  new Intent("android.intent.action.VIEW",
          Uri.parse(ProductComparisonActivity.store_url));
        startActivity(browserIntent);

      }
    });
  }


public class MyWebViewClient extends WebViewClient {
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
  }

  @Override
  public void onPageFinished(WebView view, String url) {
    dialog.dismiss();
  }

  @Override
  public void onPageStarted(WebView view, String url, Bitmap favicon) {
    dialog.show();
  }
}

}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://开发者_如何学JAVAschemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:orientation="vertical">
    <LinearLayout android:layout_height="wrap_content"
        android:id="@+id/linearLayout1" android:layout_width="match_parent"
        android:background="@drawable/top_bar_bg">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/back_to_btn"
            android:id="@+id/btn_back_bizrate" android:layout_gravity="center"
            android:layout_marginLeft="10dip"></Button>
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/text"
            android:text="Store Name" android:textColor="#ffffff"
            android:textSize="20dip" android:textStyle="bold"
            android:layout_marginLeft="12dip" android:layout_gravity="center"></TextView>
    </LinearLayout>
    <LinearLayout android:id="@+id/linearLayout2"
        android:layout_width="fill_parent" android:layout_height="350dip">
        <WebView android:layout_height="fill_parent"
            android:layout_width="fill_parent" android:id="@+id/web_storesite"></WebView>
    </LinearLayout>
    <LinearLayout android:layout_height="wrap_content"
        android:id="@+id/linearLayout3" android:layout_width="match_parent"
        android:background="@drawable/tab_bar_bg">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/prev_icon"
            android:id="@+id/btn_store_prev" android:layout_marginLeft="60dip"
            android:layout_gravity="center"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/btn_store_next"
            android:background="@drawable/next_icon" android:layout_marginLeft="40dip"
            android:layout_gravity="center"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/globe_icon"
            android:id="@+id/btn_store_globe" android:layout_marginLeft="80dip"
            android:layout_gravity="center"></Button>
    </LinearLayout>
</LinearLayout>


ComponentInfo{com.shopzilla.android.common/com.shopzilla.android.product.ProductStoreActivity} : ,tells that ProductStoreActivity is not detected, check in AndroidManifest file , whether you have specified the activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜