Error:
02/01 14:12:04: Launching app
$ adb push /Users/Kamran/AndroidStudioProjects/App/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.kami2017.app
$ adb shell pm install -r "/data/local/tmp/com.kami2017.app"
Success
$ adb shell am start -n "com.kami2017.app/com.kami2017.app.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 2284 on device emulator-5554
W/System: ClassLoader referenced unknown path: /data/app/com.kami2017.app-1/lib/x86
[ 02-01 14:12:28.511 1531: 1552 D/ ]
HostConnection::get() New Host Connection established 0x85a8d240, tid 1552
I/InstantRun: Instant Run Runtime started. Android package is com.kami2017.app, real application class is null.
W/System: ClassLoader referenced unknown path: /data/app/com.kami2017.app-1/lib/x86
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/AndroidRuntime: Shutting down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kami2017.app, PID: 2284
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kami2017.app/com.kami2017.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
at com.kami2017.app.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Application terminated.
我认为您没有在 xml 文件中为您的 Web 视图提供任何 id。您正在尝试访问该 Web 视图。
仅供参考,请查看以下链接:在Android的对话框中加载webview时获取void android.webkit.WebView.loadUrl?
您的 Web 视图为空。您是否从活动中的 xml 文件为 Web 视图创建了实例?
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
或者,您应该以编程方式创建新的 Web 视图:
WebView webView = new WebView(this);