2013-03-15 50 views
0

我正在一個應用程序中,我掃描的QR碼,並使用我打開相關的PDF。 這是我的代碼獲取java.lang.NullPointerException在Android的webView

if(uri.contains("abc")) 
       { 
    WebView webview= new WebView(getApplicationContext()); 

    webview.getSettings().setJavaScriptEnabled(true); 
    webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + uri); 

,但我的應用程序崩潰,我越來越java.lang.NullPointerException。 請幫幫我。每一個幫助將不勝感激。 這裏是我的錯誤日誌

03-15 18:26:03.150: I/Adreno200-EGLSUB(4541): <ConfigWindowMatch:2081>: Format RGBA_8888. 
03-15 18:26:03.160: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x519b7000 size:3010560 offset:2396160 fd:66 
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Default preview format: 17/yuv420sp 
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Screen resolution: Point(480, 320) 
03-15 18:26:03.610: D/CameraConfigurationManager(4541): preview-size-values parameter: 640x480,640x368,512x288,384x288,352x288,320x240,176x144 
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Camera resolution: Point(512, 288) 
03-15 18:26:03.620: D/CameraConfigurationManager(4541): Setting preview size: Point(512, 288) 
03-15 18:26:03.780: D/CameraManager(4541): Calculated framing rect: Rect(60, 40 - 420, 280) 
03-15 18:26:03.900: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x51f16000 size:6184960 offset:5570560 fd:72 
03-15 18:26:04.100: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x525fc000 size:1843200 offset:1228800 fd:75 
03-15 18:26:05.140: D/-heap(4541): GC_FOR_ALLOC freed 1322K, 22% free 6798K/8611K, paused 82ms 
03-15 18:26:06.340: D/DecodeHandler(4541): Found barcode in 267 ms 
03-15 18:26:06.360: D/-heap(4541): GC_FOR_ALLOC freed 1363K, 24% free 6817K/8867K, paused 19ms 
03-15 18:26:06.380: D/CaptureActivityHandler(4541): Got decode succeeded message 
03-15 18:26:06.530: D/MediaPlayer(4541): start() mUri is null 
03-15 18:26:08.510: W/dalvikvm(4541): threadid=1: thread exiting with uncaught exception (group=0x40af39f0) 
03-15 18:26:08.520: E/AndroidRuntime(4541): FATAL EXCEPTION: main 
03-15 18:26:08.520: E/AndroidRuntime(4541): java.lang.NullPointerException 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.ViewConfiguration.get(ViewConfiguration.java:333) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.View.<init>(View.java:2711) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.View.<init>(View.java:2757) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.ViewGroup.<init>(ViewGroup.java:419) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.webkit.WebView.<init>(WebView.java:1092) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.webkit.WebView.<init>(WebView.java:1075) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.webkit.WebView.<init>(WebView.java:1064) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.webkit.WebView.<init>(WebView.java:1054) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.webkit.WebView.<init>(WebView.java:1045) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at com.google.zxing.client.android.result.URIResultHandler.handleButtonPress(URIResultHandler.java:146) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at com.google.zxing.client.android.result.ResultButtonListener.onClick(ResultButtonListener.java:38) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.View.performClick(View.java:3528) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.view.View$PerformClick.run(View.java:14235) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.os.Handler.handleCallback(Handler.java:605) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.os.Handler.dispatchMessage(Handler.java:92) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.os.Looper.loop(Looper.java:137) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at android.app.ActivityThread.main(ActivityThread.java:4424) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 
03-15 18:26:08.520: E/AndroidRuntime(4541):  at dalvik.system.NativeStart.main(Native Method) 
+0

你需要在webview中打開哪個URL? – 2013-03-15 12:58:33

+0

我通過掃描QR碼獲取網址。通過掃描得到的字符串包含說abc,那麼它應該顯示與它相關的pdf。否則應該只是打開與QR碼相關的網址。 – Prinkal 2013-03-15 13:09:41

回答

0

您的WebView流動在空氣中。在做任何事情之前附加它來查看層次結構或通過xml佈局創建webview。

相關問題