TL/DR: An exception occurred during the creation of a fragment referenced from a higher-level layout XML. This exception caused the higher-level layout inflation to fail, but the initial exception was not reported; only the higher-level inflation failure shows up in the stack trace. To find the root cause, you have to catch and log the initial exception.
The initial cause of the error could be a wide variety of things, which is why there are so many different answers here as to what fixed the problem for each person. For some, it had to do with the id, class, or name attributes. For others it was due to a permissions issue or a build setting. For me, those didn’t fix the problem; instead there was a drawable resource that existed only in drawable-ldrtl-xhdpi, instead of in an applicable place like drawable.
But those are just details. The big-picture problem is that the error message that shows up in logcat doesn’t describe the exception that started it all. When a higher-level layout XML references a fragment, the fragment’s onCreateView() is called. When an exception occurs in a fragment’s onCreateView() (for example while inflating the fragment’s layout XML), it causes the inflation of the higher-level layout XML to fail. This higher-level inflation failure is what gets reported as an exception in the error logs. But the initial exception doesn’t seem to travel up the chain well enough to be reported.
Given that situation, the question is how to expose the initial exception, when it doesn’t show up in the error log.
The solution is pretty straightforward: Put a try/catch block around the contents of the fragment’s onCreateView(), and in the catch clause, log the exception:
public View onCreateView(LayoutInflater inflater, ViewGroup contnr, Bundle savedInstSt) {
try {
mContentView = inflater.inflate(R.layout.device_detail_frag, null);
// ... rest of body of onCreateView() ...
} catch (Exception e) {
Log.e(TAG, "onCreateView", e);
throw e;
}
}
It may not be obvious which fragment class’s onCreateView() to do this to, in which case, do it to each fragment class that’s used in the layout that caused the problem. For example, in the OP’s case, the app’s code where the exception occurred was
at android.app.Activity.setContentView(Activity.java:1901)
which is
setContentView(R.layout.activity_main);
So you need to catch exceptions in the onCreateView() of any fragments referenced in layout activity_main.
In my case, the root cause exception turned out to be
Caused by: android.content.res.Resources$NotFoundException: Resource
"com.example.myapp:drawable/details_view" (7f02006f) is not a
Drawable (color or path): TypedValue{t=0x1/d=0x7f02006f a=-1
r=0x7f02006f}
This exception didn’t show up in the error log until I caught it in onCreateView() and logged it explicitly. Once it was logged, the problem was easy enough to diagnose and fix (details_view.xml existed only under the ldrtl-xhdpi folder, for some reason). The key was catching the exception that was the root of the problem, and exposing it.
It doesn’t hurt to do this as a boilerplate in all your fragments’ onCreateView() methods. If there is an uncaught exception in there, it will crash the activity regardless. The only difference is that if you catch and log the exception in onCreateView(), you won’t be in the dark as to why it happened.
P.S. I just realized this answer is related to @DaveHubbard’s, but uses a different approach for finding the root cause (logging vs. debugger).
Класс из которого идет вызов нового активити
| Java | ||
|
Register layout
<?xml version=»1.0″ encoding=»utf-8″?>
<android.support.constraint.ConstraintLayout 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=»com.kaytus.customdev.RegisterActivi ty»>
<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLangRus»
android:layout_width=»143dp»
android:layout_height=»129dp»
android:layout_marginEnd=»116dp»
android:layout_marginStart=»116dp»
android:layout_marginTop=»16dp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:srcCompat=»@mipmap/ic_rus» />
<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLangEn»
android:layout_width=»157dp»
android:layout_height=»141dp»
android:layout_marginBottom=»180dp»
android:layout_marginEnd=»111dp»
android:layout_marginStart=»111dp»
android:background=»@color/colorWhite»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintHorizontal_bias=»0.545″
app:layout_constraintStart_toStartOf=»parent»
app:srcCompat=»@mipmap/ic_eng» />
<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnSignIn»
android:layout_width=»115dp»
android:layout_height=»104dp»
android:layout_marginBottom=»35dp»
android:layout_marginStart=»32dp»
android:layout_marginTop=»373dp»
android:background=»@color/colorWhite»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toEndOf=»@+id/igBtnLog»
app:layout_constraintTop_toTopOf=»parent»
app:layout_constraintVertical_bias=»0.755″
app:srcCompat=»@mipmap/ic_register» />
<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLog»
android:layout_width=»92dp»
android:layout_height=»98dp»
android:layout_marginBottom=»35dp»
android:layout_marginEnd=»32dp»
android:layout_marginTop=»378dp»
android:background=»@color/colorWhite»
android:scaleType=»fitStart»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toStartOf=»@+id/igBtnSignIn»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:layout_constraintVertical_bias=»0.755″
app:srcCompat=»@mipmap/ic_login» />
</android.support.constraint.ConstraintLayout>
Login layout
<?xml version=»1.0″ encoding=»utf-8″?>
<android.support.constraint.ConstraintLayout 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=»com.kaytus.customdev.LoginActivity» >
<EditText
android:id=»@+id/etLogTxt»
android:layout_width=»213dp»
android:layout_height=»38dp»
android:layout_marginEnd=»100dp»
android:layout_marginTop=»52dp»
android:ems=»10″
android:hint=»@string/etHintLog»
android:inputType=»textPersonName»
android:textSize=»14sp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/imageView3″ />
<EditText
android:id=»@+id/etRegTxt»
android:layout_width=»211dp»
android:layout_height=»wrap_content»
android:layout_marginEnd=»100dp»
android:layout_marginTop=»24dp»
android:ems=»10″
android:hint=»@string/etHintReg»
android:inputType=»textPersonName»
android:textSize=»14sp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/etLogTxt» />
<ImageView
android:id=»@+id/imageView3″
android:layout_width=»127dp»
android:layout_height=»103dp»
android:layout_marginStart=»16dp»
android:layout_marginTop=»24dp»
android:contentDescription=»@android:string/untitled»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:srcCompat=»@mipmap/ic_login» />
<ImageButton
android:id=»@+id/ieBtnLogOk»
android:layout_width=»wrap_content»
android:layout_height=»wrap_content»
android:layout_marginBottom=»69dp»
android:layout_marginTop=»47dp»
android:background=»@drawable/ic_launcher_foreground»
android:contentDescription=»@android:string/ok»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/etRegTxt»
app:srcCompat=»@mipmap/ic_buttonok» />
</android.support.constraint.ConstraintLayout>
On Android 5.0/ 5.1, it can’t resolve the WebView layout as it thrown Resources NotFoundException
And I’m been searched over stackoverflow and Google Bug Tracker and seems it’s known bug cause by AndroidX AppCompat 1.1.0:
Link 1
Link 2
Link 3
And based on the community reporting, this following bug is fixed on AndroidX AppCompat 1.2.0 already.
It’s there any timeline for the C# binding of the library available? Since my current supporting apps need to compatible with Android 5.0 and 5.1 as well and we are now currently progressing for Android SDK 29 update as well as Support Library to AndroidX Lib migration.
And based on the community seems revert to AppCompat 1.0.2 seems doesn’t have any issue but currently Xamarin.AndroidX.Migration doesn’t allow me to do that as Google.Material Library need AppCompat 1.1.0
Android.Views.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView ---> Java.Lang.Reflect.InvocationTargetException: ---> Android.Content.Res.Resources+NotFoundException: String resource ID #0x2040003
at android.content.res.Resources$NotFoundException: String resource ID #0x2040003
at at android.content.res.Resources.getText(Resources.java:299)
at at android.content.res.Resources.getString(Resources.java:385)
at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
at at android.webkit.WebView.<init>(WebView.java:554)
at at android.webkit.WebView.<init>(WebView.java:489)
at at android.webkit.WebView.<init>(WebView.java:472)
at at android.webkit.WebView.<init>(WebView.java:459)
at at java.lang.reflect.Constructor.newInstance(Native Method)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
at at android.app.Activity.performCreate(Activity.java:5990)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at at android.app.ActivityThread.access$800(ActivityThread.java:151)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:135)
at at android.app.ActivityThread.main(ActivityThread.java:5254)
at at java.lang.reflect.Method.invoke(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:372)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
--- End of inner exception stack trace ---
at java.lang.reflect.InvocationTargetException
at at java.lang.reflect.Constructor.newInstance(Native Method)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
at at android.app.Activity.performCreate(Activity.java:5990)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at at android.app.ActivityThread.access$800(ActivityThread.java:151)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:135)
at at android.app.ActivityThread.main(ActivityThread.java:5254)
at at java.lang.reflect.Method.invoke(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:372)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
at Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
at at android.content.res.Resources.getText(Resources.java:299)
at at android.content.res.Resources.getString(Resources.java:385)
at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
at at android.webkit.WebView.<init>(WebView.java:554)
at at android.webkit.WebView.<init>(WebView.java:489)
at at android.webkit.WebView.<init>(WebView.java:472)
at at android.webkit.WebView.<init>(WebView.java:459)
at ... 28 more
--- End of inner exception stack trace ---
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <55654ebe9f2a48e6bade2862bb243f94>:0
at BaseAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00009] in BaseAppCompatActivity.cs:38
at BaseToolbarAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00001] in BaseToolbarAppCompatActivity.cs:30
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <55654ebe9f2a48e6bade2862bb243f94>:0
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
at android.view.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView
at at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
at at android.app.Activity.performCreate(Activity.java:5990)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at at android.app.ActivityThread.access$800(ActivityThread.java:151)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:135)
at at android.app.ActivityThread.main(ActivityThread.java:5254)
at at java.lang.reflect.Method.invoke(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:372)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
at Caused by: java.lang.reflect.InvocationTargetException
at at java.lang.reflect.Constructor.newInstance(Native Method)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at ... 25 more
at Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
at at android.content.res.Resources.getText(Resources.java:299)
at at android.content.res.Resources.getString(Resources.java:385)
at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
at at android.webkit.WebView.<init>(WebView.java:554)
at at android.webkit.WebView.<init>(WebView.java:489)
at at android.webkit.WebView.<init>(WebView.java:472)
at at android.webkit.WebView.<init>(WebView.java:459)
at ... 28 more
- Remove From My Forums
-
Question
-
User1763 posted
Hi,
My code is
Main.axml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/MyButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/Hello" /> <fragement android:name="test.fragement.example.Fragment1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>and Activity1.cs
public class Activity1 : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); } }and Fragment1.cs
namespace test.fragement.example { public class Fragment1 : Fragment { public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); } public override View OnCreateView(LayoutInflater inflater, ViewGroup grp, Bundle bundle) { base.OnCreateView(inflater, grp, bundle); View vw = inflater.Inflate(Resource.Layout.frag1, grp, true); return vw; } } }This code is throwing an error for me. Stack trace
Android.Views.InflateException: Binary XML file line #1: Error inflating class fragement at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:616 at Android.App.Activity.SetContentView (int) [0x0006b] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:3119 at test.fragement.example.Activity1.OnCreate (Android.OS.Bundle) [0x00009] in c:Monotest.fragement.exampletest.fragement.exampleActivity1.cs:22 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:1490 at (wrapper dynamic-method) object.4b6fec41-0b84-4cbb-85e3-f821d04add6e (intptr,intptr,intptr) <IL 0x00017, 0x00043> --- End of managed exception stack trace --- android.view.InflateException: Binary XML file line #1: Error inflating class fragement at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) at android.view.LayoutInflater.inflate(LayoutInflater.java:408) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207) at android.app.Activity.setContentView(Activity.java:1657) at test.fragement.example.Activity1.n_onCreate(Native Method) at test.fragement.example.Activity1.onCreate(Activity1.java:28) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: android.view.fragement in loader dalvik.system.PathClassLoader[/data/app/test.fragement.example-1.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) at java.lang.ClassLoader.loadClass(ClassLoader.java:551) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at android.view.LayoutInflater.createView(LayoutInflater.java:471) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) ... 21 moreHow to solve this ?
Answers
-
User7668 posted
What a numpty. I have put the namespace in the path for the classname now and of course it works. Sorry for wasting everyone’s time
-
Marked as answer by
Thursday, June 3, 2021 12:00 AM
-
Marked as answer by
Как искать ответ самому.
Видим ругается на Error inflating class com.google.android.material.navigation.NavigationView
гуглим com.google.android.material.navigation.navigationview implementation
нагугливается, что это com.shreyaspatil
Удивляемся. Пока гуглили заметили, что в пустом проекте можно попробывать сделать через визард активностей.
Пробуем. И видим.
implementation ‘androidx.navigation:navigation-fragment:2.3.0’
implementation ‘androidx.navigation:navigation-ui:2.3.0’
ок. открываем лайоут .
становимся на com.google.android.material.navigation.NavigationView
нажимаем аккорд Ctrl+B — мой любимый — перейти туда где это было определено.
попадаем в класс
мотаем вверх смотрим
package com.google.android.material.navigation;
подымем взгляд еще выше на заголовок окна и видим
com.google.android.material:material:1.1.0@aar
Мое первое предположение оказалось ложным.
Возвращаемся на лайоут.
Редим предпросмотра. Серыми квадратами рисуется, то что не смогла система правильно распознать.
Забыли подключить или написали неправильно.
Режим текстового просмотра. Что нибудь подчеркивается. Значки предупреждения в виде дерева
Студия максимально старается подсказать.
Пробуйте.
К сожалению, В вашем случае скорее всего дело в стили заданном в манифесте для активити.
Не очевидный момент. Докопаться самому через отладку сложно. item name=»windowActionBar» false должно быть
https://stackoverflow.com/questions/52397840/cause…
Содержание
- InflateException, Error inflating class TextView #1183
- Comments
- Step 1: Are you in the right place?
- Step 2: Describe your environment
- Step 3: Describe the problem:
- Steps to reproduce:
- Observed Results:
- Expected Results:
- Relevant Code:
- [Solved-4 Solutions] Error inflating class fragment
- Error Description:
- Solution 1:
- Solution 2:
- Pattern #1
- Solution 3:
- Solution 4:
- Related Searches to Error inflating class fragment
- Error inflating class com.facebook.drawee.view.SimpleDraweeView #74
- Comments
- Solve Method
InflateException, Error inflating class TextView #1183
Step 1: Are you in the right place?
Step 2: Describe your environment
- Android device: Note 8
- Android OS version: Api 25
- Google Play Services version: 11.8.0
- Firebase/Play Services SDK version: 11.8.0
- FirebaseUI version: 3.2.2
Step 3: Describe the problem:
I recieved the following error upon start up
Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView
Steps to reproduce:
- Start the app, the app should fail upon start up
Observed Results:
03-09 16:04:12.294 18290-18290/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.udacity.gradle.builditbigger, PID: 18290 java.lang.RuntimeException: Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) Caused by: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class TextView Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue at android.content.res.TypedArray.getColorStateList(TypedArray.java:545) at android.widget.TextView. (TextView.java:1137) at android.widget.TextView. (TextView.java:1038) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:75) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:71) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103) at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) at android.view.LayoutInflater.rInflate(LayoutInflater.java:865) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828) at android.view.LayoutInflater.inflate(LayoutInflater.java:525) at android.view.LayoutInflater.inflate(LayoutInflater.java:427) at android.view.LayoutInflater.inflate(LayoutInflater.java:378) at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:383) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323) at android.support.v7.app.AppCompatDelegateImplV9.onPostCreate(AppCompatDelegateImplV9.java:170) at android.support.v7.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:97) at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1207) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2975) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) 03-09 16:04:13.142 18330-18330/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.udacity.gradle.builditbigger, PID: 18330 java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue at android.content.res.TypedArray.getColorStateList(TypedArray.java:545) at android.widget.TextView. (TextView.java:1137) at android.widget.TextView. (TextView.java:1038) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:75) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:71) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:67) at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753) at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261) at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243) at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621) at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onCreate(AuthMethodPickerActivity.java:84) at android.app.Activity.performCreate(Activity.java:6977) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6823) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
Expected Results:
- i expected to show the normal login screen like it did in the past.
Relevant Code:
The text was updated successfully, but these errors were encountered:
Источник
[Solved-4 Solutions] Error inflating class fragment
Error Description:
We get the Error
Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
- when we switch via the portrait and the landscape mode and when we use fragments. The xml is:
click below button to copy the code. By — android tutorial — team
- If we switch via landscape and portrait mode everything works fine. But when we click on the fragment and then switch to the other mode we get the error.
click below button to copy the code. By — android tutorial — team
Solution 1:
click below button to copy the code. By — android tutorial — team
- And also make sure that the Activity that is using the fragment(s) extends FragmentActivity instead of the regular Activity to get the FragmentActivity class.
click below button to copy the code. By — android tutorial — team
Solution 2:
- The exception android.view.InflateException: Binary XML file line: #. Error inflating class fragment might happen if you manipulate with getActivity() inside your fragment before onActivityCreated() get called. In such case you receive a wrong activity reference and can’t rely on that.
- For instance the next pattern is wrong:
click below button to copy the code. By — android tutorial — team
Pattern #1
click below button to copy the code. By — android tutorial — team
Solution 3:
- Make sure your Activity extends FragmentActivity.
Solution 4:
- The solution for is the order of super.onCreate and setContentView within the FragmentActivity
click below button to copy the code. By — android tutorial — team
World’s No 1 Animated self learning Website with Informative tutorials explaining the code and the choices behind it all.
Источник
Hi.
I’ve tried to inflate this guy on adapter, but don’t work!
I’m using the last version.
android.view.InflateException: Binary XML file line #7: Error inflating class com.facebook.drawee.view.SimpleDraweeView.
The text was updated successfully, but these errors were encountered:
Is there anything else in the error message? That should probably be fb:placeholderImage= instead of app:placeholderImage=
@IanChilds, This hasn’t relation with the problem. If I remove this line, the problem still happens.
I hava the same trouble
Solve Method
You should only call Fresco.initialize once. Your Application class would be a good place. Doing it in each Activity is wrong.
add : Fresco.initialize(this); to your Application class.
@ppamorim I have solve this problem.
add :Fresco.initialize(this); to your Application.
Thanks for your response andforce
This is so tricky. The error message seems totally irrelevant with the solution.
I have placed the Fresco.initialize(this); in my application, but still error is there.
@OverRide
protected void onCreate(Bundle savedInstanceState)
<
Above is the code. Please Please Please Help me Friends.
In case you want to implement using a fragment as would be? I have the same problem as everyone else. Best Regards!
Is this the same stack trace as issue #395?
you guys sure you registered the application in the manifest? its a small step,but your context wont be valid when you try to init Fresco without
android:name=»your application name»
I have the same problem too
how can i solve it?
ok,I solved it.
just put
and ,it works now.
thanks it worked
@ManMegh @vivian8725118 You should only call Fresco.initialize once. Your Application class would be a good place. Doing it in each Activity is wrong.
Thanks bro worked perfectly though not using fresco am using picasso.
Regards
On Fri, Oct 9, 2015 at 7:32 AM, andforce notifications@github.com wrote:
@ManMegh https://github.com/ManMegh @vivian8725118
https://github.com/vivian8725118 You should only call Fresco.initialize
once. Your Application class would be a good place. Doing it in each
Activity is wrong.
—
Reply to this email directly or view it on GitHub
#74 (comment).
I would like more of your tutorials how can i get them.
Regards
On Sat, Oct 10, 2015 at 11:07 AM, christopher pius ndugo wrote:
Thanks bro worked perfectly though not using fresco am using picasso.
Regards
On Fri, Oct 9, 2015 at 7:32 AM, andforce notifications@github.com wrote:
@ManMegh https://github.com/ManMegh @vivian8725118
https://github.com/vivian8725118 You should only call
Fresco.initialize once. Your Application class would be a good place. Doing
it in each Activity is wrong.
—
Reply to this email directly or view it on GitHub
#74 (comment).
In my case writing Fresco.initialize(this); before setContentView(R.layout.activity_home); worked
My problem was not specifing the whole path com.facebook.drawee.view.SimpleDraweeView (I had just SimpleDraweeView ). IF that is not your case, check the line of XML file on which the error occured.
I have the same problem and none of the solutions above is working for me.
@iDaniel19 paste in your XML
I found the problem . I had FacebookSdk.sdkInitialize(this); instead of Fresco.initialize(this);.
@iDaniel19 Glad you solved it. Cheers!
use following version, and you can initialize fresco in Application class
Источник
Вопрос:
У меня есть эта проблема, которая пытается убить меня.
В Lollipop (API 22) каждый раз в моем приложении я показываю веб-просмотр, сбой приложения.
У меня несколько сбоев в моей консоли разработчика Android, связанных с этим событием.
Не нужно говорить, что он работает на Android 4, 6 и 7.
Чтение трассировки стека (опубликовано в конце этого сообщения), что-то меня пугает
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
Я искал в сгенерированном R.java без везения, очевидно, потому что идентификатор не существует, но стоит попробовать.
Похоже, что проблема вокруг проблемы связана с тем, как леденец обрабатывает веб-просмотр. Я начал новый AVD с lollipop на основе устройства, которое я нашел в репортере аварии в GDC, и я могу воспроизвести проблему.
Пожалуйста, помогите мне!
Полная трассировка стека:
android.view.InflateException: Binary XML file line #7: 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 it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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 it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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.WebView.<init>(WebView.java:472)
at android.webkit.WebView.<init>(WebView.java:459)
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 it.artecoop.ibreviary.WebViewFragment.onCreateView(WebViewFragment.java:67)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
Ответ №1
Предупреждение: этот обходной путь может также сломать некоторые вещи; подробности смотрите в комментариях
Если вы хотите надуть WebView из макета XML, вы можете заключить его в симпатичный маленький подкласс (на основе ответа ikostet):
public class LollipopFixedWebView extends WebView {
public LollipopFixedWebView(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
}
public static Context getFixedContext(Context context) {
return context.createConfigurationContext(new Configuration());
}
}
ОБНОВЛЕНИЕ: теперь еще приятнее с Kotlin
class LollipopFixedWebView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : WebView(context.createConfigurationContext(Configuration()), attrs, defStyleAttr, defStyleRes)
Ответ №2
если вы используете “androidx.appcompat: appcompat: 1.1.0”, попробуйте вместо “androidx.appcompat: appcompat: 1.0.2”.
Кажется, что 1.1.0 не обрабатывает ошибку с веб-просмотром в Android 5.1.1.
Ответ №3
Попробуйте использовать веб-просмотр:
mWebView = new WebView(getActivity().createConfigurationContext(new Configuration()));
Ответ №4
Мой совет – использовать пользовательскую/новую Configuration только тогда, когда “оригинальная” вызывает проблемы, поэтому только на Lollipop. Код @SpaceBizon работал хорошо до Android 8.x, на 9 и Q (текущая бета) каждое нажатие на выбор /AlertDialog не будет показывать AlertDialog выбора AlertDialog, вместо этого происходит утечка памяти… ниже фиксированного метода getFixedContext с “iffed” правильной версией код
public class LollipopFixedWebView extends WebView {
public LollipopFixedWebView(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
}
private static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
return context.createConfigurationContext(new Configuration());
return context;
}
}
Ответ №5
Если вы используете androidx.appcompat: appcompat: 1.1.0, либо перейдите на androidx.appcompat: appcompat: 1.0.2, либо, если вы хотите использовать тему DayNight, переопределите applyOverrideConfiguration в своей деятельности следующим образом. (Примечание. Для этого требуется перезапуск приложения при переключении с темной темы на светлую и наоборот).
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode == AppConstants.appContext.resources.configuration.uiMode)) {
return
}
super.applyOverrideConfiguration(overrideConfiguration)
}
Ответ №6
戴 文锦 был прав и для меня.
Но понижение версии androidx.appcompat: appcompat: 1.1.0 до 1.0.2 не удалось.
Я понизил все мои ранее обновленные версии Androidx с
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04'
implementation 'androidx.viewpager2:viewpager2:1.0.0-beta04'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.core:core:1.2.0-alpha04'
вернуться к
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'
implementation 'androidx.viewpager2:viewpager2:1.0.0-beta03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0-rc01'
implementation 'androidx.core:core:1.2.0-alpha03'
Напоминание о том, что код Googles далеко не без ошибок и хорошо протестирован, и что кто-то никогда не должен обновлять версии легкомысленно.
Ответ №7
/**
* Customized WebView to avoid crashing on Android 5 and 6 (API level 21 to 23)
* If the Android System WebView is old and is not updated, the WebView view inflation fails.
* To reproduce the issue, try on OS 5 or 6 with Android System WebView 72.0.3626.76 (this version is just a reference point from being which we saw no crashes)
*/
class BrilliantWebView : WebView {
companion object {
private fun getBrilliantContext(context: Context?) =
if (!OSUtils.hasNougat()) // OS < 24 or OS < 7.0
context?.createConfigurationContext(Configuration())
else
context
}
constructor(context: Context?) : super(getBrilliantContext(context))
constructor(context: Context?, attrs: AttributeSet?) : super(getBrilliantContext(context), attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(getBrilliantContext(context), attrs, defStyleAttr)
}
Ответ №8
Мне удалось воспроизвести сбой API 21 в эмуляторе.
Поэтому я попытался добавить это к реализации, как описано в документации:
dependencies {
def appcompat_version = "1.1.0"
implementation "androidx.appcompat:appcompat:$appcompat_version"
// For loading and tinting drawables on older versions of the platform
implementation "androidx.appcompat:appcompat-resources:$appcompat_version"
}
Добавление appcompat-resources не решило проблему.
Возможно, в будущем появится версия, но я хотел бы упомянуть, что, похоже, существует дополнительная библиотека ресурсов, которая должна решить эту проблему. Поэтому, пытаясь исправить это с помощью новой версии appcompat, добавьте библиотеку appcompat-resources с той же версией.
Возвращение к androidx.appcompat:appcompat:1.0.2 решило проблему как обходной путь.
Ответ №9
Если вы не полагаетесь на переключение тем DayNight (или другие события UiMode), вы можете добавить android:configChanges="uiMode" в манифест активности веб-просмотра, чтобы AppCompatDelegate не обновлял конфигурацию ресурсов и, таким образом, не нарушал инфляцию веб-просмотра. Обнаружил этот обходной путь, изучив исходный код изменений 1.1.0-rc01 в 1.1.0.
Понижение до 1.1.0-rc01 также должно работать.