使用webur时使用webview,app停止工作

时间:2014-05-07 08:25:06

标签: android android-webview

我刚开始开发并且我遇到了webview的问题,当使用loadurl时,我有这个错误,你能帮忙吗?

堆栈追踪:

05-07 03:58:06.860: W/dalvikvm(866): threadid=1: thread exiting with uncaught exception (group=0xb2abdba8)
05-07 03:58:06.870: E/AndroidRuntime(866): FATAL EXCEPTION: main
05-07 03:58:06.870: E/AndroidRuntime(866): Process: com.newtest, PID: 866
05-07 03:58:06.870: E/AndroidRuntime(866): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.newtest/com.newtest.MainActivity}: java.lang.NullPointerException
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.os.Handler.dispatchMessage(Handler.java:102)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.os.Looper.loop(Looper.java:136)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread.main(ActivityThread.java:5017)
05-07 03:58:06.870: E/AndroidRuntime(866):  at java.lang.reflect.Method.invokeNative(Native Method)
05-07 03:58:06.870: E/AndroidRuntime(866):  at java.lang.reflect.Method.invoke(Method.java:515)
05-07 03:58:06.870: E/AndroidRuntime(866):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-07 03:58:06.870: E/AndroidRuntime(866):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-07 03:58:06.870: E/AndroidRuntime(866):  at dalvik.system.NativeStart.main(Native Method)
05-07 03:58:06.870: E/AndroidRuntime(866): Caused by: java.lang.NullPointerException
05-07 03:58:06.870: E/AndroidRuntime(866):  at com.newtest.MainActivity.onCreate(MainActivity.java:25)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.Activity.performCreate(Activity.java:5231)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-07 03:58:06.870: E/AndroidRuntime(866):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-07 03:58:06.870: E/AndroidRuntime(866):  ... 11 more

布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.newtest.MainActivity$PlaceholderFragment" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

Java类文件:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.os.Build;

public class MainActivity extends ActionBarActivity {
    private WebView mWebV;
    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebV = (WebView) findViewById(R.id.webView1);
        mWebV.getSettings().setJavaScriptEnabled(true);
        mWebV.loadUrl("http://www.google.com");

    }

0 个答案:

没有答案