I'm trying to add payment from for my application. I use that library for that. I added it to my project. I'm also try delete from gradle and re-install it but it gave same error again.
Here my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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=".OdemeSayfasi">
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"/>
</LinearLayout>
In run time I got error which is:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slidework3, PID: 23708
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidework3/com.example.slidework3.OdemeSayfasi}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.slidework3.OdemeSayfasi.onCreate(OdemeSayfasi.kt:22)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This error is very long so I get only first parts of it.
How can I solve it? I try to inflate layout but I can't solve it. I'm waiting for your advices and help.
I tried to replicate it and noticed this message alongside with what you have shown:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
The reason being the library uses MDC.
I had to change the existing app theme applied into Material Design Component(MDC) based, so to make avoid the error; Example: In under style.xml:
<style name="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
Edit: If you don't want to affect the apptheme, you can just apply a Material Component theme to just the payview.
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"
android:theme="#style/Theme.MaterialComponents"/>
If you want to customise your payview, just create a custom theme whose parent based on Theme.MaterialComponents .
Related
I am totally new to android development and trying to learn it by my own, I have done some coding in xml file but when I run the application, app has install in my phone but not opening.
Here is the error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sumita.yourhelp, PID: 6407
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sumita.yourhelp/com.sumita.yourhelp.MainActivity}: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2994)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:797)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:831)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.sumita.yourhelp.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7227)
at android.app.Activity.performCreate(Activity.java:7218)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
at android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:1217)
at android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:1094)
at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1173)
at android.content.res.Resources.loadColorStateList(Resources.java:1076)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:541)
at android.view.View.<init>(View.java:5180)
at android.widget.TextView.<init>(TextView.java:867)
at android.widget.Button.<init>(Button.java:166)
at android.widget.Button.<init>(Button.java:141)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:80)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:75)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:650)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:797)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:831)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.sumita.yourhelp.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7227)
at android.app.Activity.performCreate(Activity.java:7218)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1766)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
And here is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="11dp"
android:gravity="center_horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="258dp"
android:contentDescription="#string/About"
android:scaleType="fitXY"
android:src="#drawable/ic_contact_us" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Aboutus"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="?android:attr/colorFocusedHighlight"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="12"
android:hint="enter number"
android:inputType="number" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/material_dynamic_neutral40"
android:text="contact us"
android:textColor="#color/black"/>
</LinearLayout>
Two relevant parts of your error log.
This section points to a problem in line 39 of your layout file, inflating an AppCompatButton.
Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class androidx.appcompat.widget.AppCompatButton
There's also this in your error log:
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
So, taken together, your error log suggests that there's a problem with a color that's being used in an AppCompatButton on line 39 of your layout XML.
If you look at that line in your layout file, you'll see this:
android:textColor="#color/black"/>
Taken together, I would guess that you haven't defined the color you've called black correctly. Try and replace it with #android:color/black and see if that works. If it does, then you need to fix whatever color you've defined for black in your resources files.
I have two project one uses color statelist selector in NavigationView to change the background color of items in Navigation Drawer on different state of interactions.
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemBackground="#color/nav_bgstate_list" <------
app:itemIconTint="#color/nav_state_list" <------
app:itemTextColor="#color/nav_state_list" <------
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
These three lines causes error but when I remove them, it works fine.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Item checked -->
<item android:color="#color/brand" android:state_checked="true" />
<!-- Item pressed -->
<item android:color="#color/black" android:state_pressed="true" />
<!-- Item default -->
<item android:color="#color/brand70" />
</selector>
I copied the same code into another project and it started throwing bunch of errors. The log is below
2021-06-09 07:49:13.564 12895-12895/ca.company.project.betaversion E/AndroidRuntime: FATAL EXCEPTION: main
Process: ca.company.project.betaversion, PID: 12895
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.company.project.betaversion/ca.company.project.betaversion.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: Drawable ca.company.project.betaversion:color/nav_bgstate_list with resource ID #0x7f0600d9
Caused by: android.content.res.Resources$NotFoundException: File res/color/nav_bgstate_list.xml from drawable resource ID #0x7f0600d9
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.content.Context.getDrawable(Context.java:605)
at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:455)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:147)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:135)
2021-06-09 07:49:13.569 12895-12895/ca.company.project.betaversion E/AndroidRuntime: at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.TintTypedArray.getDrawable(TintTypedArray.java:83)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:196)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:122)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:189)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:807)
... 36 more
I checked minSdk version, compilied sdk version, themes, gradle version, dependencies with their versions etc. and everything is same, nothing is different. I know I should be using drawable states instead of color state but I don't understand why it is working in other project but in the another one.
Edit 1
I found out that the crash was happening because of I set the itembackground with color state selector. itemIconTint and itemTextColor works fine with color state selectors. Only itemBackground crashes whenever I try to set the state selector there so I found one solution mentioned here, basically I need to add checked android:checkable="true" but even after adding this it crashed. I don't know why.
Edit 2
So I realized color state selector is working on newer version of android > 10 but not on the older version of android.
I am trying to make an app for my WordPress website using json... the app debug successfully but not started it stopped working when i try to open app.. Please Help
Here is activity_main.xml File Please Check this out
activity_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view">
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressbar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Logcat File
2019-11-22 08:33:19.368 2734-2734/? D/AndroidRuntime: Shutting down VM
2019-11-22 08:33:19.369 2734-2734/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ats.sarkarijobs, PID: 2734
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ats.sarkarijobs/com.ats.sarkarijobs.MainActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
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: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.ats.sarkarijobs-3/base.apk"],nativeLibraryDirectories=[/data/app/com.ats.sarkarijobs-3/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.ats.sarkarijobs.MainActivity.onCreate(MainActivity.java:35)
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)
I have added activity_main.xml and logcat file please check this out.
Your project is AndroidX enabled, but you are not using AndroidX dependencies in your app level build.gradle.
So, inside your project
Navigate to the Refactor menu
Click on Migrate to AndroidX
You might have to also make changes to your XML layouts-
Change android.support.design.widget.CoordinatorLayout to androidx.coordinatorlayout.widget.CoordinatorLayout and android.support.v7.widget.RecyclerView to androidx.recyclerview.widget.RecyclerView
and likewise CardView to androidx.cardview.widget.CardView
I'm having some problem with BottomNavigationView from design support library.
I am using it in my activity_main.xml:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
app:itemIconSize="16dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"
app:menu="#menu/main"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The app crashes when inflating that xml. The full stack trace of the exception is below:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frolo.musp.dev/com.alexfrolov.mp.main.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:651)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.alexfrolov.mp.main.MainActivity.onCreate(MainActivity.java:165)
at android.app.Activity.performCreate(Activity.java:7074)
at android.app.Activity.performCreate(Activity.java:7065)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:220)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:93)
at android.content.res.Resources.getColorStateList(Resources.java:1034)
at android.content.Context.getColorStateList(Context.java:631)
at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:67)
at android.support.design.internal.BottomNavigationMenuView.createDefaultColorStateList(BottomNavigationMenuView.java:467)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:101)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:86)
The versions of all support libs and the version of compileSdk are same. I really don't understand what a hell is that. Can anybody explain me please?
Thanks
I had this problem and it baffled me for a day or so. Basically, the BottomNav wants a colorstatelist defined for textColorSecondary in your theme as opposed to a just plain color. So I went from:
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#295055</item>
to
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#color/secondary_textcolor</item>
where secondary_textcolor equals
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="#295055"/>
<item android:state_enabled="false" android:color="#color/disabled"/>
</selector>
I wasted a lot of time adding and removing dependencies trying to find this solution.
The problem is in your question title
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
It means that you are using a resource that is not existent. I cannot know which it is but this is how you will fix. Go to the file #menu/main and remove all attributes for icons. You can leave the text. Add one by one to check which one is the problem. It is most likely to be that your icons have been mistakenly placed inside the folder drawable-24 instead of drawable or a higher android API folder than the one you are testing on. Sometimes we make those mistakes.
Also note that some attributes only apply starting a certain android API. Consider checking the attributes starting with app.
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"
Every single Toast.makeText in my app is giving me a stack trace similar to this:
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.application, PID: 8843
android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.widget.Toast.makeText(Toast.java:263)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.widget.Toast.makeText(Toast.java:263)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=16; index=1191
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1151)
at android.content.res.TypedArray.getString(TypedArray.java:195)
at android.support.v7.widget.TintTypedArray.getString(TintTypedArray.java:142)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:243)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:165)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:80)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:70)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
These are some sample Toast.makeText calls that are causing it
Toast.makeText(ReportActivity.this, "Reported for " + reportType, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.network_unavailable, Toast.LENGTH_SHORT).show();
It all started when we upgraded our Gradle libraries and started using these versions
compileSdkVersion 27
buildToolsVersion '27.0.1'
The bug apparently occurs when using support library 26+, on API 25 and lower, and is supposedly fixed in Oreo.
See: https://issuetracker.google.com/issues/64053344
The fix in my case was to change the fontFamily defined in my default theme, by extracting sans-serif-light to a string resource, that is going from this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">sans-serif-light</item>
</style>
To this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">#string/default_font</item>
</style>
with in my strings.xml:
<string name="default_font" translatable="false">sans-serif-light</string>
My Toast callings was with getBaseContext(). I just change it to getApplicationContext() to solve the problem.
I solved the crashing from the Toast.makeText entries all throughout the app by doing a global search for fontFamily and deleting the entries.
It seems like the font family was being defined and the new build tools and SDK didn't like that.