获取java.lang.NullPointerException在Android webView中

时间:2013-03-15 12:57:42

标签: android

我正在开发一个应用程序,在其中我扫描QR码并使用它我打开与之相关的pdf。 这是我的代码

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)

1 个答案:

答案 0 :(得分:0)

您的WebView正在流动。在执行任何操作之前将其附加到视图层次结构或通过xml布局创建webview。