3

I'm using an android studio with androidx in the latest version. I have a TextInputLayout in my app, which makes the app crashes when adding any style to it!

this is my part of xml:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/saveNameID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

and this is the logcat error:

2019-01-30 22:41:59.537 1980-1980/hossein.yusefpour.sinamobile E/AndroidRuntime: FATAL EXCEPTION: main
Process: hossein.yusefpour.sinamobile, PID: 1980
android.view.InflateException: Binary XML file line #51: Binary XML file line #51: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class <unknown>
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 androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManagerImpl.java:147)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6578)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 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:240)
    at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
Hossein Yousefpour
  • 3,827
  • 3
  • 23
  • 35
  • 2
    "Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)." – Bö macht Blau Jan 30 '19 at 19:31
  • @Mike please make those question as duplicate which really are duplicate... its very tough to the figure out that the issues causing the problems are same .. the they are to really different question.. due to your act it become tough for me (new developer ) to understand how these two things are same and how to solve my problem using this data.. so please for god sack for the developers like us don't do such heroic acts.. ---Thank you – Raj Kumar Sep 27 '19 at 09:37
  • 1
    @RajKumar Sorry, but this isn't a tutorial site for beginners. We're here to maintain a repository of quality answers to specific programming issues, and marking duplicates to consolidate a given issue's various solutions is part of that. Furthermore, questions will be closed as duplicates for their ultimate solutions, when appropriate, not necessarily the posts' contents. The given Exception has a clear, singular root cause – an invalid theme on the `Context` used to instantiate a library `View` – and that would be the same for any configuration which results in that particular Exception. – Mike M. Nov 10 '19 at 06:36
  • 1
    @RajKumar If you don't see how those answers can fix the stated problem, then you might do well to spend some time learning Android basics; in this case, themes, how they're applied, and which `Context`s have the right ones. A full guide for that topic is out-of-scope for Stack Overflow. And, as always, you're free to post a new question with your specific problem, if those answers already provided are not working for you. – Mike M. Nov 10 '19 at 06:37

0 Answers0