I've got problem with TextInputLayout from material components for android. When I add style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
to my TextInputLayout, app has crashed. All code .xml is like fragment.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".CreatorFragment"
android:background="@color/cardview_dark_background">
<LinearLayout
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@ id/imageView"
android:layout_width="match_parent"
android:layout_height="164dp"
android:foregroundGravity="center_vertical|center|center_horizontal"
android:src="@drawable/ic_photo"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="244dp"
android:hint="Title"
app:counterEnabled="true"
app:counterMaxLength="18"
app:counterOverflowTextColor="?attr/colorPrimary"
android:textColorHint = "?attr/colorPrimary"
app:hintTextColor = "?attr/colorPrimary"
app:prefixTextColor = "?attr/colorPrimary"
app:boxStrokeColor = "?attr/colorPrimary"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</FrameLayout>
I have in manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar">
And error code from logcat is:
2021-10-30 14:42:48.810 6850-6850/com.example.diary E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
0.2% 1421/msm_irqbalance: 0% user 0.2% kernel
0.2% 2678/com.android.phone: 0% user 0.1% kernel / faults: 2 minor
0.1% 692/zygote64: 0% user 0.1% kernel / faults: 194 minor
0.1% 3419/irq/81-90b6300.: 0% user 0.1% kernel
0% 10914/com.miui.securitycenter.remote: 0% user 0% kernel / faults: 749 minor
0.1% 1/init: 0% user 0% kernel
0.1% 27/ksoftirqd/2: 0% user 0.1% kernel
0% 793/[email protected]: 0% user 0% kernel
0.1% 22074/logcat: 0.1% user 0% kernel
0.1% 25230/kworker/2:0: 0% user 0.1% kernel
0% 8/ksoftirqd/0: 0% user 0% kernel
0% 12/rcuop/0: 0% user 0% kernel
0% 538/ueventd: 0% user 0% kernel
0% 813/[email protected]: 0% user 0% kernel
0% 867/mi_thermald: 0% user 0% kernel
0% 1220/statsd: 0% user 0% kernel
0% 2179/hvdcp_opti: 0% user 0% kernel
0% 3369/kworker/1:0: 0% user 0% kernel
0% 5029/transport: 0% user 0% kernel
0% 21135/kworker/u17:0: 0% user 0% kernel
0% 27171/com.miui.notification:remote: 0% user 0% kernel
0% 30321/com.google.android.youtube: 0% user 0% kernel / faults: 6 minor
0% 9/rcu_preempt: 0% user 0% kernel
0% 10/rcu_sched: 0% user 0% kernel
0% 13/rcuos/0: 0% user 0% kernel
0% 19/ksoftirqd/1: 0% user 0% kernel
0% 22/rcuop/1: 0% user 0% kernel
0% 30/rcuop/2: 0% user 0% kernel
0% 38/rcuop/3: 0% user 0% kernel
0% 560/servicemanager: 0% user 0% kernel
0% 691/netd: 0% user 0% kernel / faults: 18 minor
0% 759/qrtr_rx: 0% user 0% kernel
0% 803/[email protected]: 0% user 0% kernel
0% 1200/cameraserver: 0% user 0% kernel
0% 1440/qcrild: 0% user 0% kernel / faults: 6 minor
0% 2382/cds_ol_rx_threa: 0% user 0% kernel
0% 3252/kworker/3:1: 0% user 0% kernel
0% 3264/kworker/2:2: 0% user 0% kernel
0% 3331/charge_logger: 0% user 0% kernel
0% 16507/kworker/u17:1: 0% user 0% kernel
0% 17866/com.mi.android.globallauncher: 0% user 0% kernel / faults: 3 minor
0% 21372/kworker/0:0: 0% user 0% kernel
0% 30216/kworker/2:1: 0% user 0% kernel
0% 5515/com.android.se: 0% user 0% kernel
3.3% TOTAL: 1.5% user 1.3% kernel 0% iowait 0.3% irq 0.1% softirq
CPU usage from 1438307732ms to 1438307732ms ago (1970-01-01 01:00:00.000 to 1970-01-01 01:00:00.000) with 0% awake:
0% TOTAL: 0% user 0% kernel
2021-10-30 14:42:48.714 6850-6850/? E/m.example.diar: Unknown bits set in runtime_flags: 0x8000
2021-10-30 14:42:48.714 6850-6850/? E/m.example.diar: Unknown bits set in runtime_flags: 0x8000
2021-10-30 14:42:48.714 6850-6850/? E/m.example.diar: Unknown bits set in runtime_flags: 0x8000
2021-10-30 14:42:52.914 6850-6850/com.example.diary E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.diary, PID: 6850
android.view.InflateException: Binary XML file line #40 in com.example.diary:layout/fragment_creator: Binary XML file line #40 in com.example.diary:layout/fragment_creator: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #40 in com.example.diary:layout/fragment_creator: 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:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at com.example.diary.CreatorFragment.onCreateView(CreatorFragment.kt:37)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2106)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7565)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
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:469)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:428)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at com.example.diary.CreatorFragment.onCreateView(CreatorFragment.kt:37)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2106)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7565)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Line #40 it is after 'style' in TextInputLayout. How can I fix it?
CodePudding user response:
Change your app theme to Theme.MaterialComponents and probably you'll be fine
CodePudding user response:
Stacktrace exception causes start from the outside and work their way in - the first thing you see is the exception that caused the crash, but if you read down, you'll see what caused that exception, and then what caused that one and so on, until you get to the root of the problem.
If you go down each section (starting with Caused by
) you'll eventually get to this (the last section, i.e. where the problem started):
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
That's probably enough info! ;)