2011-06-07 35 views
1

當一個活動中的webview中傳遞的url(該URL是從上一個活動傳遞的)中獲得NullPointerException,但是當控件進入webview.loadurl(url)時,它顯示NullPointerException。我檢查了在傳遞的url中有一個值,但我仍然不知道爲什麼會出現錯誤?爲什麼我傳遞一個url到webview時會得到一個NullPointerExeption?

這是錯誤:

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) 

代碼:

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://schemas.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> 
+0

看來,你的捆綁包實例是空的。您能否顯示一段代碼,將「url」參數傳遞到ProductStoreActivity的位置? – 2011-06-07 10:21:42

回答

0

ComponentInfo {com.shopzilla.android.common/COM。 shopzilla.android.product.ProductStoreActi vity}:,告訴ProductStoreActivity未被檢測到,檢查AndroidManifest文件中是否指定了活動。

+0

是的,它已經被檢查,它已經在Android清單文件中。 – 2011-06-07 10:19:57

相關問題