[MaterialTimePicker] Error Inflating MaterialTimePicker, missing layout_height attribute
See original GitHub issueDescription: With the latest update to 1.3.0-beta01, my app crashes when trying to show the MaterialTimePicker dialog. Here is the stack trace of the crash:
Caused by: android.view.InflateException: Binary XML file line #46 in [my_app_id]:layout/material_timepicker_dialog: Error inflating class com.google.android.material.timepicker.TimePickerView
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:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at com.google.android.material.timepicker.MaterialTimePicker.onCreateView(MaterialTimePicker.java:205)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #27 in [my_app_id]:layout/material_timepicker: Binary XML file line #35: You must supply a layout_height attribute.
Caused by: java.lang.UnsupportedOperationException: Binary XML file line #35: You must supply a layout_height attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:830)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:8232)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:8429)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:2023)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1917)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:89)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1261)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1117)
at android.view.LayoutInflater.inflate(LayoutInflater.java:654)
2020-12-28 15:22:07.350 1705-1705/[my_app_id] E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at com.google.android.material.timepicker.TimePickerView.<init>(TimePickerView.java:100)
at com.google.android.material.timepicker.TimePickerView.<init>(TimePickerView.java:95)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at com.google.android.material.timepicker.MaterialTimePicker.onCreateView(MaterialTimePicker.java:205)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I don’t define the time picker in a layout file at all in my app, only programmatically. The crash seems to be coming from the library’s .xml layout file from what I can see in the trace.
Expected behavior: No crash when executing the dialog.show(…) method.
Source code:
private lateinit var materialTimePicker: MaterialTimePicker
...
materialTimePicker = MaterialTimePicker.Builder()
.setTitleText(title)
.setHour(jodaLocalTime.hourOfDay)
.setMinute(jodaLocalTime.minuteOfHour)
.setTimeFormat(TimeFormat.CLOCK_12H)
.build()
// Show the material time picker
materialTimePicker.show(requireActivity().supportFragmentManager, materialTimePicker.toString())
Android API version: Android 11 (30)
Material Library version: 1.3.0-beta01
Device: Pixel 3XL
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Error inflating class com.google.android.material.slider.Slider
I created the following theme: <style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <!-- Add attributes here ...
Read more >TextInputLayout | Android Developers
Returns the text color used by the hint in both the collapsed and expanded states, or null if no color has been set....
Read more >Issue Related To Error Inflating Class Android.Widget ...
Open Error inflating class com.google.android.material.timepicker. ... Error Inflating MaterialTimePicker, missing layout_height attribute.
Read more >Diff - platform/frameworks/base - Google Git
In case of + * failure or if no transport is currently active, this method returns ... Material.TimePicker"> - <item name="legacyMode">true</item> + <item ......
Read more >Visual Feedback: Dialogs, Snackbars and Toasts
The card with ID card_mystery has two extra attributes defined: ... library also provides MaterialTimePicker and MaterialDatePicker classes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cpferschy Thank you! I saw that line in there, but didn’t think to change anything since I was not explicitly inheriting the old theme. I changed my modified
MaterialTimePickerTheme
style parent from""
to"ThemeOverlay.MaterialComponents.TimePicker"
and it worked again.Source:
I see the same behavior with an API level 26 Samsung device.
Edit: This was introduced with version 1.3.0-alpha04 of the library.