Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton - android

Although there is a similar question, it does not give me a solution. When I'm trying to use com.google.android.material.floatingactionbutton.FloatingActionButton it runs well. But if I try to use com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton, it gives errors.
My code in the XML file:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/book_profile_write_review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:contentDescription="#string/author_name"
android:text="#string/book_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
logcat:
2019-11-14 12:30:21.997 21326-21326/com.bookaholic.shahad.bookaholicbd E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bookaholic.shahad.bookaholicbd, PID: 21326
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bookaholic.shahad.bookaholicbd/com.bookaholic.shahad.bookaholicbd.activities.BookProfile}: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2974)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
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 android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.bookaholic.shahad.bookaholicbd.activities.BookProfile.onCreate(BookProfile.java:20)
at android.app.Activity.performCreate(Activity.java:7258)
at android.app.Activity.performCreate(Activity.java:7249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:200)
Can you please help me?

From your logcat
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
So add a material theme for your app/current activity will fix this issue
1) add dependency* (latest / more stable version)
implementation 'com.google.android.material:material:1.2.0-alpha01'
2) Create a new theme
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Add attributes here -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="textAppearanceButton">#style/AppTextAppearance.Button</item>
</style>
<!--To fix rendering in preview -->
<style name="AppTextAppearance.Button" parent="TextAppearance.MaterialComponents.Button">
<item name="android:textAllCaps">true</item>
</style>
change parent material theme according to you parent="Theme.MaterialComponents.*
3) change app theme or current activity theme in manifest
android:theme="#style/MyMaterialTheme"
or
<activity android:name=".MyActivity"
android:theme="#style/MyMaterialTheme"> </activity>
4) If you found any rendering issue in previews, adding themes to ExtendedFloatingActionButton will fix this
Failed to find '#attr/textAppearanceButton' in current theme.
add theme to ExtendedFloatingActionButton android:theme="#style/MyMaterialTheme"
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="#style/MyMaterialTheme"
android:text="ExtendedFab"
app:icon="#drawable/ic_add_a_photo_white_24dp"
/>
For more info visit Material Design Page

You need to use a an app or activity theme that is a descendant from Theme.MaterialComponents.
You can see in the trace:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

Here this one work for me
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton android:theme="#style/MyMaterialTheme" .................. />
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Add attributes here -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="textAppearanceButton">#style/AppTextAppearance.Button</item>
</style>

AndroidManifest.xml
Update your app theme to inherit from one of these themes, e.g.:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
build.gradle
dependencies {
// ...
implementation "com.google.android.material:material:1.3.0-alpha03"
}
GL
Source

I've got the same error after updating to targetSdkVersion = 32.
My activity already had a theme inheriting from MaterialComponents.
The issue was that I was setting
android:background="?selectableItemBackground"
to the ExtendedFloatingActionButton. So if you're trying to override the background, it will give you error. Remove that and it should work.

If you plan to make an Application using material Design Components, consider using Theme.MaterialComponents.* because in some occasions you will face some inflating errors regarding XML
More information about Material Design Components can be found here: MATERIAL.IO

Related

Can't use color statelist in navigationVIew Android kotlin

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.

App crashes when a CustomNoActionBar style is used for an activity

I click on a Floating Action Button that is in the main activity and when i click it, i am supposed to be in the second activity but the app crashes when i click the floating action button. The logcat was pointing to this code that was crashing the app:
setContentView(R.layout.activity_add_happy_place)
The above line which is in the onCreate method of my second activity was crashing the app. So I spent a lot of time and found out that in the AndroidManifest.xml file, the style of my second activity has a custom theme and when i removed that one line then the app wasn't crashing anymore.
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.happyplaces">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HappyPlaces">
<activity
android:name=".AddHappyPlaceActivity"
android:label="ADD HAPPY PLACE"
android:screenOrientation="portrait"
/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
CustomNoActionBarTheme:
<style name="CustomNoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
If i don't use the CustomActionBarTheme then the app doesn't crash but i want it to work because i dont need an ActionBar for that activity. How can i fix this? Thanks in advance.
Edit:
Logcat of the crash:
20 21-05-07 11:01:00.164 1909-1909/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
20 21-05-07 11:01:00.675 2267-2267/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.happyplaces, PID: 2267
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.happyplaces/com.example.happyplaces.AddHappyPlaceActivity}: android.view.InflateException: Binary XML file line #36 in com.example.happyplaces:layout/activity_add_happy_place: Binary XML file line #36 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #36 in com.example.happyplaces:layout/activity_add_happy_place: Binary XML file line #36 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #36 in com.example.happyplaces:layout/activity_add_happy_place: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.happyplaces.AddHappyPlaceActivity.onCreate(AddHappyPlaceActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
2021-05-07 11:01:00.675 2267-2267/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:463)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:422)
... 32 more
2021-05-07 11:01:00.804 2030-2126/? E/InputDispatcher: channel 'c3c4942 com.example.happyplaces/com.example.happyplaces.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
Main Activity Code:
package com.example.happyplaces
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fabAddHappyPlace.setOnClickListener {
val intent = Intent(this, AddHappyPlaceActivity::class.java)
startActivity(intent)
}
}
}
Second Activity [AddHappyPlaceActivity] Code:
package com.example.happyplaces
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_add_happy_place.*
class AddHappyPlaceActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_happy_place)
setSupportActionBar(toolbar_add_place)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar_add_place.setNavigationOnClickListener {
onBackPressed()
}
}
}
I have a toolbar in my second activity and it has a custom theme:
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar_add_place"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="#style/CustomToolbarStyle"/>
CustomToolbarStyle:
<style name="CustomToolbarStyle">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:colorControlNormal">#FFFFFF</item>
</style>
Edit:
I added a new style named Material Theme as answered by Shams. The app crashed again and this time the logcat pointed out to this line in the code of the second activity:
setSupportActionBar(toolbar_add_place)
The logcat:
2021-05-07 12:36:16.373 6086-6086/? E/ple.happyplace: Unknown bits set in runtime_flags: 0x8000
2021-05-07 12:36:19.115 6086-6086/com.example.happyplaces E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.happyplaces, PID: 6086
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.happyplaces/com.example.happyplaces.AddHappyPlaceActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:572)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:159)
at com.example.happyplaces.AddHappyPlaceActivity.onCreate(AddHappyPlaceActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
I removed these lines of code in the second activity:
setSupportActionBar(toolbar_add_place)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar_add_place.setNavigationOnClickListener {
onBackPressed()
}
The toolbar was still in the xml file and the application didn't crash this time. But i obviously want the toolbar to have onBackPressed() which i am not able to do for now.
Error inflating class com.google.android.material.textfield.TextInputLayout
Error occur when inflating TextInputLayout. Why? Because you are using TextInputLayout without inherit from Theme.MaterialComponents. So you must inherit from Theme.MaterialComponents.
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
First create material theme in style.xml
<style name="MaterialTheme"
parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
And use it in application tag in manifest
<application
android:theme="#style/MaterialTheme"
or in specific activity
<activity
android:theme="#style/AppTheme"
android:name=".ui.HomeFragmentActivity"/>
I don't have enough rep to comment so I'm leaving my comment as an answer.
Did you set the toolbar in the Layout?
For trouble shooting purposes you can try removing the appbar setup from the second activity to see if that is causing the problem.

BottomNavigationView inflating error. Resources$NotFoundException: Resource ID #0x0

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"

Binary XML file line #2 Error inflating class android.widget.RelativeLayout for try to dynamically implement theme

I have been trying to implement dynamic them in my project but for some reason its giving the following error. this is how i tried to implement it.
First i defined some custom attributes like:
<resources>
<attr name="themeWindowBackground" format="reference" />
<attr name="themeContentBackground" format="reference" />
<attr name="themeContentTextColor" format="reference" />
<attr name="themeContentTextColorOnPrimary" format="reference" />
<attr name="themeTextColorSuccess" format="reference" />
<attr name="themeTextColorFailure" format="reference" />
then i defined the custom themes in my style.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/bg_splash_screen</item>
</style>
<style name="AppTheme.Black" parent="AppTheme">
<item name="colorPrimary">#color/material_dark</item>
<item name="colorPrimaryDark">#color/material_primary_dark</item>
<item name="colorAccent">#color/material_accent</item>
<item name="themeWindowBackground">#color/dark_gray</item>
<item name="themeContentBackground">#color/dark_slate_gray</item>
<item name="themeContentTextColor">#color/white</item>
<item name="themeContentTextColorOnPrimary">#color/teal</item>
<item name="themeTextColorSuccess">#color/green</item>
<item name="themeTextColorFailure">#color/red</item>
</style>
</resources>
after that i am setting the theme using this
application.setTheme(mPreferenceRepository.savedTheme)
this the function that is geeting the saved theme
public int getSavedTheme() {
String theme = getStringFromSharedPreference(APP_THEME);
if (theme.equals(THEME_BLUE)) {
return R.style.AppTheme_Blue;
}
return R.style.AppTheme_Black;
}
now when i'm trying to apply theme in my layout or layout content using this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/themeWindowBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
the application is crashing. this is my message but i can't figure out what i'm doing wrong
Process: com.singularitybd.shellitracker, PID: 2214
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.singularitybd.shellitracker/com.singularitybd.shellitracker.view.activity.LoginActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
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 #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.singularitybd.shellitracker.view.activity.LoginActivity.onCreate(LoginActivity.kt:44)
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)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0301ba a=-1}
at android.content.res.TypedArray.getDrawable(TypedArray.java:925)
at android.view.View.<init>(View.java:4202)
at android.view.ViewGroup.<init>(ViewGroup.java:579)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785) 
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.singularitybd.shellitracker.view.activity.LoginActivity.onCreate(LoginActivity.kt:44) 
at android.app.Activity.performCreate(Activity.java:6679) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Application terminated.
if you can provide me some guidance i will be very grateful. Thank you very much.
I just had this problem occurs when I test my app on a old android phone. However it works on new android phone. I finally find out that I save the layout background image in the res\drawable-v24. Remove the image and save back at res\drawable
Hope this solve your problem
I think and as I understand your statements this problem is about second line of RelativeLayout. Try to add another picture to the background, or try typing
android:background="?attr/themeWindowBackground" ` as style.
Like this : style =?attr/themeWindowBackround
This is a old question, but I decided to answer anyway. The problem is that you are referencing to a view that does not exist.
From your log:
Binary XML file line #2: Error inflating class android.widget.RelativeLayout
You are trying to inflate a RelativeLayout that doesn't exist.
This may occur when you added a layout for landscape and you forgot to add the RelativeLayout, or it could be that you are referencing to a RelativeLayout with a incorrect id.
Make sure that the RelativeLayout actually exist and that the correct id is used hen you are referencing to it.

Material design - After I set a new color app doesn't run

I tried change a color by use a Material Design method.
But after this, when I want to run my application it's stopped work.
When I click app icon to run this one, I see this app for circa 1 second only.
I see that colors were changed but this application stops work properly.
I don't know where is a problem because I use instructions on official Android's website.
Could someone help me to resolve this problem?
Below is my code:
Styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/colorprimarydark</item>
<item name="android:windowBackground">#color/windowbackground</item>
<item name="android:textColorPrimary">#color/textcolorprimary</item>
</style>
Colors.xml:
<color name="primaryColor">#FF9800</color>
<color name="colorprimarydark">#FF3F00</color>
<color name="windowbackground">#BDBDBD</color>
<color name="textcolorprimary">#039BE5</color>
Activity.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.karol.material_test.MainActivity">
<TextView
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Logcat:
01-20 21:27:12.120 28957-28957/com.example.karol.material_test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.karol.material_test, PID: 28957
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.karol.material_test/com.example.karol.material_test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2406)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
at android.app.ActivityThread.access$1200(ActivityThread.java:152)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5538)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.karol.material_test.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6013)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466) 
at android.app.ActivityThread.access$1200(ActivityThread.java:152) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5538) 
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:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
01-20 21:27:12.510 28957-28957/com.example.karol.material_test I/Process: Sending signal. PID: 28957 SIG: 9
You need to use a Theme.AppCompat theme (or descendant) with this
activity.
Instead of: android:Theme.Material
Check this:
https://stackoverflow.com/a/21815015/4409113
And just use AppCompat in your styles or AppCompatActivity in the Java codes.

Categories

Resources