【问题标题】:What exactly does my logcat mean, and how can I fix it?我的 logcat 到底是什么意思,我该如何解决?
【发布时间】:2019-09-22 12:26:30
【问题描述】:

出于某种原因,我的应用程序喜欢在 API 23 (Marshmallow) 或更高版本上运行时运行良好。但是当它尝试在 API 22 (Lollipop) 上运行时,它会立即崩溃,我就是不明白为什么。

我试过注释掉除了最低限度之外的任何东西,但它仍然会这样做。我发现如果不注释掉所有 webview,应用程序甚至都无法启动。

这是我尝试在 Android Studio 中启动应用程序并在 API 22 上模拟 Pixel 2 时得到的 logcat。为了进一步参考,是的,我在没有自定义 WebView 类的情况下尝试了它,但它仍然抛出相同的错误。

09-22 15:07:55.644 3443-3443/? I/art: Not late-enabling -Xcheck:jni (already on)
09-22 15:07:55.727 3443-3443/test.webview W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter
 androidx.vectordrawable.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
09-22 15:07:55.749 3443-3443/test.webview I/art: Rejecting re-init on previously-failed class java.lang.Class<
androidx.core.view.ViewCompat$2>
09-22 15:07:55.750 3443-3443/test.webview I/art: Rejecting re-init on previously-failed class java.lang.Class<
androidx.core.view.ViewCompat$2>
09-22 15:07:55.808 3443-3443/test.webview I/WebViewFactory: Loading com.android.webview version 39 (5525941-x86_64
) (code 300008)
09-22 15:07:55.812 3443-3443/test.webview I/LibraryLoader: Time to load native libraries: 1 ms (timestamps 9226-
9227)
09-22 15:07:55.812 3443-3443/test.webview I/LibraryLoader: Expected native library version number "",actual native
 library version number ""
09-22 15:07:55.817 3443-3443/test.webview V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper
 (main, tid 1) {204b24c3}
09-22 15:07:55.817 3443-3443/test.webview I/LibraryLoader: Expected native library version number "",actual native
 library version number ""
09-22 15:07:55.817 3443-3443/test.webview I/chromium: [INFO:library_loader_hooks.cc(104)] Chromium logging enabled
: level = 0, default verbosity = 0
09-22 15:07:55.819 3443-3443/test.webview I/BrowserStartupController: Initializing chromium process, singleProcess
=true
09-22 15:07:55.820 3443-3443/test.webview W/art: Attempt to remove local handle scope entry from IRT, ignoring
09-22 15:07:55.827 3443-3443/test.webview W/chromium: [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
09-22 15:07:55.828 3443-3443/test.webview I/chromium: [INFO:aw_browser_main_parts.cc(65)] Load from apk succesful
, fd=31 off=46184 len=3037
09-22 15:07:55.828 3443-3443/test.webview I/chromium: [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.
pak from, fd:32 off:229484 len:1089587
09-22 15:07:55.829 3443-3467/test.webview W/AudioManagerAndroid: Requires BLUETOOTH permission
09-22 15:07:55.854 3443-3443/test.webview D/EGL_emulation: eglCreateContext: 0x7fa99e8df2a0: maj 2 min 0 rcv 2
09-22 15:07:55.855 3443-3443/test.webview D/EGL_emulation: eglMakeCurrent: 0x7fa99e8df2a0: ver 2 0 (tinfo
0x7fa99e8d4a60)
09-22 15:07:55.877 3443-3443/test.webview W/chromium: [WARNING:data_reduction_proxy_settings.cc(331)] SPDY proxy
OFF at startup
09-22 15:07:55.882 3443-3443/test.webview W/ResourceType: No known package when getting value for resource number
0x02040003
09-22 15:07:55.882 3443-3443/test.webview D/AndroidRuntime: Shutting down VM
09-22 15:07:55.883 3443-3443/test.webview E/AndroidRuntime: FATAL EXCEPTION: main
 Process: test.webview, PID: 3443
 java.lang.RuntimeException: Unable to start activity ComponentInfo{test.webview/test.webview.MainActivity}:
android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
 at android.app.ActivityThread.access$800(ActivityThread.java:151)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5254)
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.
WebView
 at android.view.LayoutInflater.createView(LayoutInflater.java:633)
 at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
 at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
 at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
 at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
 at test.webview.MainActivity.onCreate(MainActivity.java:15)
 at android.app.Activity.performCreate(Activity.java:5990)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
 at android.app.ActivityThread.access$800(ActivityThread.java:151)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5254) 
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.reflect.InvocationTargetException
 at java.lang.reflect.Constructor.newInstance(Native Method)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
 at android.view.LayoutInflater.createView(LayoutInflater.java:607)
 at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
 at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
 at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
 at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
 at test.webview.MainActivity.onCreate(MainActivity.java:15)
 at android.app.Activity.performCreate(Activity.java:5990)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
 at android.app.ActivityThread.access$800(ActivityThread.java:151)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5254)
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
 at android.content.res.Resources.getText(Resources.java:299)
 at android.content.res.Resources.getString(Resources.java:385)
 at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
 at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
 at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:
631)
 at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
 at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
 at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
 at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
 at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
 at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
 at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:
123)
 at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
 at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
 at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
 at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
 at android.webkit.WebView.<init>(WebView.java:554)
 at android.webkit.WebView.<init>(WebView.java:489)
 at android.webkit.WebV

我期待它启动(可能看起来不是最好的,因为在使用旧 API 时 webview 支持不同),但它似乎因为通货膨胀异常而崩溃? (除非我读错了)

编辑:我刚刚尝试使用 1 个 WebView 创建一个全新的应用程序,也很简单,但它也会崩溃。这是activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

</RelativeLayout>

这是 MainActivity.java

package test.webview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.webView);

        webView.loadUrl("https://google.com");
    }
}

如您所见,代码没有任何问题。那么有什么问题呢? (你也可以在 Lollipop 上自己测试一下)

【问题讨论】:

  • 发布你的 main_activity 类和它的 xml 文件 plz
  • 如果需要,请检查您是否将正确的上下文传递给您的班级
  • @mohammadRezaAbiri 我现在做了
  • @Movsac 我更新了我的问题,即使是正常的 webview 崩溃...

标签: java android webview mobile-application


【解决方案1】:

在您的 MainActivity xml 中,您已声明 NoSuggestionsWebView 类。

错误说明在您的MainActivity xml 第 17 行 NoSuggestionsWebView 无法膨胀。

您必须检查NoSuggestionsWebView 类并检查您是否正在做与操作系统相关的事情或类似的事情。

【讨论】:

  • 就是这样,即使我不使用我的自定义类(使用普通 WebView),它也会做同样的事情......
  • 再次检查我的问题,我更新了更多信息。
【解决方案2】:

原来是 AVD 包含的旧版本 Android System Webview 中的一些错误,或者是因为 AppCompat 构建版本 (1.1.0) 中的错误。按照answer 所说的去做,让我的应用程序再次运行。这对我有用,因为我在 1.1.0 中并没有真正使用任何特殊的东西,所以使用 1.0.2 对androidx.appcompat:appcompat:1.0.2 来说就很好

【讨论】:

    猜你喜欢
    • 2021-07-14
    • 2014-07-05
    • 1970-01-01
    • 2013-12-08
    • 2016-02-04
    • 1970-01-01
    • 2021-07-15
    • 2019-05-17
    • 1970-01-01
    相关资源
    最近更新 更多