我在三星SM G920F(Galaxy S6)5.1.1版中发现了Crashlytics的崩溃报告(在所有其他设备上,我没有检索到相同的错误)。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.myactivity}:
android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
这是我的网络视图的布局(样式为空样式):
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_webview_id"
style="@style/MyEmptyStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
以下是我如何将其包括在活动布局中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/my_webview_layout"
android:visibility="gone"/>
</LinearLayout>
报告的错误是XML错误,所以我提供了所有代码(简化)。这是一个单一的报告,所以它只在这个设备上发生过一次,有人能解释一下为什么吗?
编辑(完成堆栈跟踪)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.myactivity}: android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
at android.app.Fragment.performCreateView(Fragment.java:2114)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
at android.app.Activity.performCreateCommon(Activity.java:6492)
at android.app.Activity.performCreate(Activity.java:6521)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
at android.app.Fragment.performCreateView(Fragment.java:2114)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
at android.app.Activity.performCreateCommon(Activity.java:6492)
at android.app.Activity.performCreate(Activity.java:6521)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:174)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
at android.webkit.WebView.getFactory(WebView.java:2202)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
at android.view.View.<init>(View.java:3843)
at android.view.View.<init>(View.java:3954)
at android.view.ViewGroup.<init>(ViewGroup.java:513)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:553)
at android.webkit.WebView.<init>(WebView.java:498)
at android.webkit.WebView.<init>(WebView.java:481)
at android.webkit.WebView.<init>(WebView.java:468)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
at android.app.Fragment.performCreateView(Fragment.java:2114)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
at android.app.Activity.performCreateCommon(Activity.java:6492)
at android.app.Activity.performCreate(Activity.java:6521)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:167)
at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:146)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:109)
at android.webkit.WebView.getFactory(WebView.java:2202)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2197)
at android.webkit.WebView.setOverScrollMode(WebView.java:2256)
at android.view.View.<init>(View.java:3843)
at android.view.View.<init>(View.java:3954)
at android.view.ViewGroup.<init>(ViewGroup.java:513)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:553)
at android.webkit.WebView.<init>(WebView.java:498)
at android.webkit.WebView.<init>(WebView.java:481)
at android.webkit.WebView.<init>(WebView.java:468)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.mypackage.drawer.fragments.Myfragment.createContentView(Myfragment.java:50)
at com.externalpackage.app.ExternalFragment.onCreateView(ExternalFragment.java:115)
at com.externalpackage.app.LocationExternalFragment.onCreateView(LocationExternalFragment.java:65)
at com.mypackage.drawer.fragments.Myfragment.onCreateView(Myfragment.java:55)
at android.app.Fragment.performCreateView(Fragment.java:2114)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
at android.app.Activity.performCreateCommon(Activity.java:6492)
at android.app.Activity.performCreate(Activity.java:6521)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
正如西蒙·尼农所说,这就是我在应用程序中实现的方式。
在UI中膨胀Webview的活动的创建过程中,您可以尝试捕获以避免Crashlytics中产生的错误。
/**
* This element touches the UI elements
* of the application and set them up.
*/
try {
setContentView(R.layout.activity_main);
// ... further setup
} catch (Exception ex) {
transferToNoPackageFoundActivity(ex.getMessage());
}
private void transferToNoPackageFoundActivity(String errorMessage) {
Intent intent = new Intent(this, NoPackageFoundActivity.class);
intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
startActivity(intent);
finish();
}
在NoPackageFoundActivity中,您可以将用户带到Playstore下载webview包。
/**
* This field is used for presenting the user
* with an error image for no connectivity.
*/
private lateinit var mErrorImage: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_no_network)
// get the intent for the error message, if any.
val intent: Intent = intent
if (intent.hasExtra(Intent.EXTRA_INTENT)) {
println(intent.getStringExtra(Intent.EXTRA_INTENT))
}
mErrorImage = findViewById(R.id.error_image)
mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
Glide.with(this)
.load(R.drawable.ic_no_web_view_illustration)
.into(mErrorImage)
val enableButton = findViewById<Button>(R.id.error_handler_btn)
enableButton.setOnClickListener { openGooglePlayStore() }
enableButton.text = resources.getString(R.string.no_package_btn_text)
val reloadText = findViewById<TextView>(R.id.no_network_reload)
reloadText.setOnClickListener { reloadApplication() }
val errorHeadingText = findViewById<TextView>(R.id.error_heading)
val errorSubheadingText = findViewById<TextView>(R.id.error_subheading)
errorHeadingText.text = resources.getString(R.string.no_package_heading_text)
errorSubheadingText.text = resources.getString(R.string.no_package_subheading_text)
}
/**
* This is a onClickListener Handler that
* reloads the application when the user
* clicks on it.
* It starts the activity again from
*/
private fun reloadApplication() {
val intent = Intent(this, SplashScreen::class.java)
startActivity(intent)
finish()
}
private fun openGooglePlayStore() {
// you can also use BuildConfig.APPLICATION_ID
val appId = "com.google.android.webview"
val rateIntent = Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=$appId"))
var marketFound = false
// find all applications able to handle our rateIntent
val otherApps = packageManager
.queryIntentActivities(rateIntent, 0)
for (otherApp in otherApps) { // look for Google Play application
if (otherApp.activityInfo.applicationInfo.packageName
== "com.android.vending") {
val otherAppActivity = otherApp.activityInfo
val componentName = ComponentName(
otherAppActivity.applicationInfo.packageName,
otherAppActivity.name
)
// make sure it does NOT open in the stack of your activity
rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// task reparenting if needed
rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
// if the Google Play was already open in a search result
// this make sure it still go to the app page you requested
rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
// this make sure only the Google Play app is allowed to
// intercept the intent
rateIntent.component = componentName
startActivity(rateIntent)
marketFound = true
break
}
}
// if GP not present on device, open web browser
if (!marketFound) {
val webIntent = Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appId"))
startActivity(webIntent)
}
}
我的crashlytics也有同样的错误。
在Google上进行一些搜索后,当用户在手机上没有安装webview时,似乎会发生这种情况。
这听起来很奇怪,因为webview是一个系统包,但有一个bug,当用户在使用应用程序时更新webview包实际上是可能的。它并不适用于所有手机,所以它可以在一些特定的设备上复制(我想大部分是三星的…),但不适用于其他人。
我记不清具体的步骤,但有点像:
不知道该怎么处理。我想你可以看看软件包是否存在,或者注册以在软件包更新时收到通知以重新加载应用程序。在我的情况下,这确实是一个角落的情况,发生了一次或两次,我认为不需要努力解决这个问题。如果这种情况发生得更频繁,可能需要采取一些行动。
当应用程序膨胀WebView时,似乎发生了一些奇怪的事情,可能是什么。
对于NameNotFoundException:com.google.android.webview我可以推断出这可能是Google软件包的问题(用户可能使用自定义ROM而没有安装它们。)
如果你有更多关于终端错误的信息,我会说你去做,但是你必须看到你拥有的用户/users_with_this_error的比例。然后你可以看看它是否对你在这个问题上的工作有用。
从breakline的评论来看:看看这篇文章,看起来有点像同一个问题:NameNotFoundException webview
我试图将我的GLSurfaceView设置在xml布局以及其他UI元素上,并不断获得错误inflating类com.vi.cubo01。MyGLSurfaceView在LogCat. 以下是java代码: 以及xml:
我在自定义控件中膨胀MvxImageView时遇到问题。 从我所做的研究中,我发现了几个嫌疑人 > < li >我是否应该将“如果”添加到“什么”中?(我看到这是关于android地图视图膨胀错误。 < li> 我创建的用户控件是不是都错了?我看到了一个使用SetContentView()而不是inflate的建议,因为它通过mvvmcross机制传递indlate请求,但在自定义视图中没有这样的
问题内容: 您好,我是android dev和admob的新手。我正在尝试制作一个带有按钮,几个页面和底部的admob的简单测试应用程序。一切正常,直到我尝试实施admob。这是我的代码: HelloAndroid.java: main.xml: 您好android清单: logcat输出: 我正在使用GoogleAdMobAdsSdkAndroid-6.0.0。再次,我对此非常陌生,我尝试在多个
问题内容: 错误日志: 10-26 12:22:33.144 26926-26926 /?E / AndroidRuntime:致命例外:主进程:ksmk.sahip.com.ecom,PID:26926 java.lang.RuntimeException:无法启动活动ComponentInfo {ksmk.sahip.com.ecom / ksmk.sahip.com.ecom.MainAct
问题内容: 尝试运行我的应用程序时,我意外地遇到了以下错误: 下面是日志猫: 以下是Java代码: 下面是布局代码: 提前致谢 问题答案: 我通过在app / build.gradle上添加更新的cardview和appcompat解决了这一问题 然后重建项目
问题内容: 我正在尝试创建一个扩展的自定义视图。这是我的班级定义文件 : 这是在我的ghostviewscreen.xml中: 现在,我在活动中进行了: 当被调用时,抛出一个异常: 谁能告诉我为什么会出现此错误?谢谢。 问题答案: 我想我弄清楚了为什么这没用。当我应该为两个参数“ Context,AttributeSet”的情况提供构造函数时,我只为一个参数“ context”的情况提供了构造函数