material android Chip is crashing when inflated in xml layout
Even if I don't do anything in code... looks like somewhere in view class drawable is created somehow and this crashes Chip as this is not allowed... Any help welcome.
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
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.rInflate(LayoutInflater.java:866)
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 renetik.android.viewbase.CSView.inflate(CSView.java:104)
at renetik.android.viewbase.CSView.getView(CSView.java:119)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:405)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:408)
at renetik.android.viewbase.CSView.findView(CSView.java:108)
at renetik.android.extensions.view.CSViewKt.editText(CSView.kt:22)
at com.tanya.renetik.redriver.view.route.EditHouseFieldsController.<init>(EditHouseFieldsController.kt:15)
at com.tanya.renetik.redriver.view.route.started.StartedAddHouseController.<init>(StartedAddHouseController.kt:31)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:37)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:17)
at renetik.android.extensions.view.ViewKt$onClick$$inlined$apply$lambda$1.onClick(View.kt:51)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
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.UnsupportedOperationException: Do not set the background; Chip manages its own background drawable.
at com.google.android.material.chip.Chip.setBackground(Chip.java:397)
at android.view.View.<init>(View.java:5200)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.Button.<init>(Button.java:172)
at android.widget.CompoundButton.<init>(CompoundButton.java:94)
at android.widget.CheckBox.<init>(CheckBox.java:69)
at android.widget.CheckBox.<init>(CheckBox.java:65)
at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:64)
at com.google.android.material.chip.Chip.<init>(Chip.java:169)
In layout just something like this...
<com.google.android.material.chip.Chip
android:id="@+id/EditHouse_Category_Vacant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Category_Vacant" />
My theme file is simple:
<style name="DriverTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/driver_primary</item>
<item name="colorPrimaryDark">@color/driver_primary_dark</item>
<item name="colorSecondary">@color/driver_secondary</item>
</style>
</resources>
ext.kotlin_version = '1.3.0'
ext.material_version = '1.0.0'
ext.appcompat_version = '1.0.0'
ext.play_version = '16.0.0'
android material androidx material-components material-components-android
add a comment |
Even if I don't do anything in code... looks like somewhere in view class drawable is created somehow and this crashes Chip as this is not allowed... Any help welcome.
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
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.rInflate(LayoutInflater.java:866)
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 renetik.android.viewbase.CSView.inflate(CSView.java:104)
at renetik.android.viewbase.CSView.getView(CSView.java:119)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:405)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:408)
at renetik.android.viewbase.CSView.findView(CSView.java:108)
at renetik.android.extensions.view.CSViewKt.editText(CSView.kt:22)
at com.tanya.renetik.redriver.view.route.EditHouseFieldsController.<init>(EditHouseFieldsController.kt:15)
at com.tanya.renetik.redriver.view.route.started.StartedAddHouseController.<init>(StartedAddHouseController.kt:31)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:37)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:17)
at renetik.android.extensions.view.ViewKt$onClick$$inlined$apply$lambda$1.onClick(View.kt:51)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
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.UnsupportedOperationException: Do not set the background; Chip manages its own background drawable.
at com.google.android.material.chip.Chip.setBackground(Chip.java:397)
at android.view.View.<init>(View.java:5200)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.Button.<init>(Button.java:172)
at android.widget.CompoundButton.<init>(CompoundButton.java:94)
at android.widget.CheckBox.<init>(CheckBox.java:69)
at android.widget.CheckBox.<init>(CheckBox.java:65)
at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:64)
at com.google.android.material.chip.Chip.<init>(Chip.java:169)
In layout just something like this...
<com.google.android.material.chip.Chip
android:id="@+id/EditHouse_Category_Vacant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Category_Vacant" />
My theme file is simple:
<style name="DriverTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/driver_primary</item>
<item name="colorPrimaryDark">@color/driver_primary_dark</item>
<item name="colorSecondary">@color/driver_secondary</item>
</style>
</resources>
ext.kotlin_version = '1.3.0'
ext.material_version = '1.0.0'
ext.appcompat_version = '1.0.0'
ext.play_version = '16.0.0'
android material androidx material-components material-components-android
What theme are you using for the activity that has thisChip
in it? Does this theme defineandroid:background
?
– Ben P.
Nov 12 at 22:21
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43
add a comment |
Even if I don't do anything in code... looks like somewhere in view class drawable is created somehow and this crashes Chip as this is not allowed... Any help welcome.
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
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.rInflate(LayoutInflater.java:866)
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 renetik.android.viewbase.CSView.inflate(CSView.java:104)
at renetik.android.viewbase.CSView.getView(CSView.java:119)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:405)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:408)
at renetik.android.viewbase.CSView.findView(CSView.java:108)
at renetik.android.extensions.view.CSViewKt.editText(CSView.kt:22)
at com.tanya.renetik.redriver.view.route.EditHouseFieldsController.<init>(EditHouseFieldsController.kt:15)
at com.tanya.renetik.redriver.view.route.started.StartedAddHouseController.<init>(StartedAddHouseController.kt:31)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:37)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:17)
at renetik.android.extensions.view.ViewKt$onClick$$inlined$apply$lambda$1.onClick(View.kt:51)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
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.UnsupportedOperationException: Do not set the background; Chip manages its own background drawable.
at com.google.android.material.chip.Chip.setBackground(Chip.java:397)
at android.view.View.<init>(View.java:5200)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.Button.<init>(Button.java:172)
at android.widget.CompoundButton.<init>(CompoundButton.java:94)
at android.widget.CheckBox.<init>(CheckBox.java:69)
at android.widget.CheckBox.<init>(CheckBox.java:65)
at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:64)
at com.google.android.material.chip.Chip.<init>(Chip.java:169)
In layout just something like this...
<com.google.android.material.chip.Chip
android:id="@+id/EditHouse_Category_Vacant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Category_Vacant" />
My theme file is simple:
<style name="DriverTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/driver_primary</item>
<item name="colorPrimaryDark">@color/driver_primary_dark</item>
<item name="colorSecondary">@color/driver_secondary</item>
</style>
</resources>
ext.kotlin_version = '1.3.0'
ext.material_version = '1.0.0'
ext.appcompat_version = '1.0.0'
ext.play_version = '16.0.0'
android material androidx material-components material-components-android
Even if I don't do anything in code... looks like somewhere in view class drawable is created somehow and this crashes Chip as this is not allowed... Any help welcome.
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.material.chip.Chip
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.rInflate(LayoutInflater.java:866)
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 renetik.android.viewbase.CSView.inflate(CSView.java:104)
at renetik.android.viewbase.CSView.getView(CSView.java:119)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:405)
at renetik.android.viewbase.CSViewController.getView(CSViewController.java:408)
at renetik.android.viewbase.CSView.findView(CSView.java:108)
at renetik.android.extensions.view.CSViewKt.editText(CSView.kt:22)
at com.tanya.renetik.redriver.view.route.EditHouseFieldsController.<init>(EditHouseFieldsController.kt:15)
at com.tanya.renetik.redriver.view.route.started.StartedAddHouseController.<init>(StartedAddHouseController.kt:31)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:37)
at com.tanya.renetik.redriver.view.route.started.StartedRouteMapController$onCreate$2.invoke(StartedRouteMapController.kt:17)
at renetik.android.extensions.view.ViewKt$onClick$$inlined$apply$lambda$1.onClick(View.kt:51)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
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.UnsupportedOperationException: Do not set the background; Chip manages its own background drawable.
at com.google.android.material.chip.Chip.setBackground(Chip.java:397)
at android.view.View.<init>(View.java:5200)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.Button.<init>(Button.java:172)
at android.widget.CompoundButton.<init>(CompoundButton.java:94)
at android.widget.CheckBox.<init>(CheckBox.java:69)
at android.widget.CheckBox.<init>(CheckBox.java:65)
at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:64)
at com.google.android.material.chip.Chip.<init>(Chip.java:169)
In layout just something like this...
<com.google.android.material.chip.Chip
android:id="@+id/EditHouse_Category_Vacant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Category_Vacant" />
My theme file is simple:
<style name="DriverTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/driver_primary</item>
<item name="colorPrimaryDark">@color/driver_primary_dark</item>
<item name="colorSecondary">@color/driver_secondary</item>
</style>
</resources>
ext.kotlin_version = '1.3.0'
ext.material_version = '1.0.0'
ext.appcompat_version = '1.0.0'
ext.play_version = '16.0.0'
android material androidx material-components material-components-android
android material androidx material-components material-components-android
edited Nov 13 at 16:39
asked Nov 11 at 9:02
Renetik
1,9482135
1,9482135
What theme are you using for the activity that has thisChip
in it? Does this theme defineandroid:background
?
– Ben P.
Nov 12 at 22:21
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43
add a comment |
What theme are you using for the activity that has thisChip
in it? Does this theme defineandroid:background
?
– Ben P.
Nov 12 at 22:21
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43
What theme are you using for the activity that has this
Chip
in it? Does this theme define android:background
?– Ben P.
Nov 12 at 22:21
What theme are you using for the activity that has this
Chip
in it? Does this theme define android:background
?– Ben P.
Nov 12 at 22:21
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43
add a comment |
3 Answers
3
active
oldest
votes
Just my small workaround after one day of battling :/
class ChipCrashWorkaround(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: Chip(context, attrs, defStyleAttr)
constructor (context: Context, attrs: AttributeSet?)
: this(context, attrs, R.attr.chipStyle)
constructor (context: Context) : this(context, null)
override fun setBackground(background: Drawable) = try
super.setBackground(background)
catch (ex: UnsupportedOperationException)
warn(ex)
override fun setBackgroundDrawable(background: Drawable) = try
super.setBackgroundDrawable(background)
catch (ex: UnsupportedOperationException)
warn(ex)
Well I can see clearly that somehow drawable is applied probably from theme to my chip even if I disable all customizations everywhere.. Wtf I don't know but have to move forward...
add a comment |
Which version of the library are you using? The exception is being thrown because chip manages its own background and doesn't support View#setBackground. Is it possible that a parent of your chip instance is trying to set the chip's background?
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
add a comment |
Ok I found it, I was using this code to create top level layout:
view = FrameLayout(ContextThemeWrapper(this.context(), R.style.CSNavigationContainer))
And inside of this layout I have set white background what should be ok but...
Now I see what this ContextThemeWrapper actually do:
The specified theme will be applied on top of the base context's theme.
So by this my context theme was modified to contain background with white color and this somehow went to other views created later with this context and this crashed Chip as it don't allow background.
So I have to stop using ContextThemeWrapper , maybe I misunderstood real purpose, I wanted to apply style to my view programmatically, what actually worked, but it modified whole theme.
So I found library paris for aplying styles programatically and changed that code to:
view = FrameLayout(context()).apply style(R.style.CSNavigationContainer)
now it works with the same style.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247229%2fmaterial-android-chip-is-crashing-when-inflated-in-xml-layout%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just my small workaround after one day of battling :/
class ChipCrashWorkaround(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: Chip(context, attrs, defStyleAttr)
constructor (context: Context, attrs: AttributeSet?)
: this(context, attrs, R.attr.chipStyle)
constructor (context: Context) : this(context, null)
override fun setBackground(background: Drawable) = try
super.setBackground(background)
catch (ex: UnsupportedOperationException)
warn(ex)
override fun setBackgroundDrawable(background: Drawable) = try
super.setBackgroundDrawable(background)
catch (ex: UnsupportedOperationException)
warn(ex)
Well I can see clearly that somehow drawable is applied probably from theme to my chip even if I disable all customizations everywhere.. Wtf I don't know but have to move forward...
add a comment |
Just my small workaround after one day of battling :/
class ChipCrashWorkaround(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: Chip(context, attrs, defStyleAttr)
constructor (context: Context, attrs: AttributeSet?)
: this(context, attrs, R.attr.chipStyle)
constructor (context: Context) : this(context, null)
override fun setBackground(background: Drawable) = try
super.setBackground(background)
catch (ex: UnsupportedOperationException)
warn(ex)
override fun setBackgroundDrawable(background: Drawable) = try
super.setBackgroundDrawable(background)
catch (ex: UnsupportedOperationException)
warn(ex)
Well I can see clearly that somehow drawable is applied probably from theme to my chip even if I disable all customizations everywhere.. Wtf I don't know but have to move forward...
add a comment |
Just my small workaround after one day of battling :/
class ChipCrashWorkaround(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: Chip(context, attrs, defStyleAttr)
constructor (context: Context, attrs: AttributeSet?)
: this(context, attrs, R.attr.chipStyle)
constructor (context: Context) : this(context, null)
override fun setBackground(background: Drawable) = try
super.setBackground(background)
catch (ex: UnsupportedOperationException)
warn(ex)
override fun setBackgroundDrawable(background: Drawable) = try
super.setBackgroundDrawable(background)
catch (ex: UnsupportedOperationException)
warn(ex)
Well I can see clearly that somehow drawable is applied probably from theme to my chip even if I disable all customizations everywhere.. Wtf I don't know but have to move forward...
Just my small workaround after one day of battling :/
class ChipCrashWorkaround(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: Chip(context, attrs, defStyleAttr)
constructor (context: Context, attrs: AttributeSet?)
: this(context, attrs, R.attr.chipStyle)
constructor (context: Context) : this(context, null)
override fun setBackground(background: Drawable) = try
super.setBackground(background)
catch (ex: UnsupportedOperationException)
warn(ex)
override fun setBackgroundDrawable(background: Drawable) = try
super.setBackgroundDrawable(background)
catch (ex: UnsupportedOperationException)
warn(ex)
Well I can see clearly that somehow drawable is applied probably from theme to my chip even if I disable all customizations everywhere.. Wtf I don't know but have to move forward...
edited Nov 11 at 19:21
answered Nov 11 at 18:47
Renetik
1,9482135
1,9482135
add a comment |
add a comment |
Which version of the library are you using? The exception is being thrown because chip manages its own background and doesn't support View#setBackground. Is it possible that a parent of your chip instance is trying to set the chip's background?
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
add a comment |
Which version of the library are you using? The exception is being thrown because chip manages its own background and doesn't support View#setBackground. Is it possible that a parent of your chip instance is trying to set the chip's background?
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
add a comment |
Which version of the library are you using? The exception is being thrown because chip manages its own background and doesn't support View#setBackground. Is it possible that a parent of your chip instance is trying to set the chip's background?
Which version of the library are you using? The exception is being thrown because chip manages its own background and doesn't support View#setBackground. Is it possible that a parent of your chip instance is trying to set the chip's background?
answered Nov 12 at 18:26
wcshi
262
262
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
add a comment |
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Hi, you mean like programmatically ? Or how exactly I can set background from parent ?
– Renetik
Nov 13 at 16:35
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Well sure I know what is causing the crash... don't know how the color background gets applied though ... some background magic here...
– Renetik
Nov 13 at 16:41
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
Could you please verify whether the crash is reproducible in a very simple sample app, without using any of your custom views?
– wcshi
Nov 13 at 19:57
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
did you look at the solution I found ? There is explained very clearly how this happened stackoverflow.com/a/53287528/925135 , its not bug in material library for sure, but consequence of usage of ContextThemeWrapper. It's fore sure reproducible easily. But for sure Chip should not throw exception like this, it should warn and ignore background form theme or something... Thats my opinion.
– Renetik
Nov 13 at 23:01
1
1
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
Hi Renetik, thanks for the explanation and suggestion. I filed a ticket to make the change, you can track the progress at: b.corp.google.com/issues/119564663
– wcshi
Nov 14 at 20:35
add a comment |
Ok I found it, I was using this code to create top level layout:
view = FrameLayout(ContextThemeWrapper(this.context(), R.style.CSNavigationContainer))
And inside of this layout I have set white background what should be ok but...
Now I see what this ContextThemeWrapper actually do:
The specified theme will be applied on top of the base context's theme.
So by this my context theme was modified to contain background with white color and this somehow went to other views created later with this context and this crashed Chip as it don't allow background.
So I have to stop using ContextThemeWrapper , maybe I misunderstood real purpose, I wanted to apply style to my view programmatically, what actually worked, but it modified whole theme.
So I found library paris for aplying styles programatically and changed that code to:
view = FrameLayout(context()).apply style(R.style.CSNavigationContainer)
now it works with the same style.
add a comment |
Ok I found it, I was using this code to create top level layout:
view = FrameLayout(ContextThemeWrapper(this.context(), R.style.CSNavigationContainer))
And inside of this layout I have set white background what should be ok but...
Now I see what this ContextThemeWrapper actually do:
The specified theme will be applied on top of the base context's theme.
So by this my context theme was modified to contain background with white color and this somehow went to other views created later with this context and this crashed Chip as it don't allow background.
So I have to stop using ContextThemeWrapper , maybe I misunderstood real purpose, I wanted to apply style to my view programmatically, what actually worked, but it modified whole theme.
So I found library paris for aplying styles programatically and changed that code to:
view = FrameLayout(context()).apply style(R.style.CSNavigationContainer)
now it works with the same style.
add a comment |
Ok I found it, I was using this code to create top level layout:
view = FrameLayout(ContextThemeWrapper(this.context(), R.style.CSNavigationContainer))
And inside of this layout I have set white background what should be ok but...
Now I see what this ContextThemeWrapper actually do:
The specified theme will be applied on top of the base context's theme.
So by this my context theme was modified to contain background with white color and this somehow went to other views created later with this context and this crashed Chip as it don't allow background.
So I have to stop using ContextThemeWrapper , maybe I misunderstood real purpose, I wanted to apply style to my view programmatically, what actually worked, but it modified whole theme.
So I found library paris for aplying styles programatically and changed that code to:
view = FrameLayout(context()).apply style(R.style.CSNavigationContainer)
now it works with the same style.
Ok I found it, I was using this code to create top level layout:
view = FrameLayout(ContextThemeWrapper(this.context(), R.style.CSNavigationContainer))
And inside of this layout I have set white background what should be ok but...
Now I see what this ContextThemeWrapper actually do:
The specified theme will be applied on top of the base context's theme.
So by this my context theme was modified to contain background with white color and this somehow went to other views created later with this context and this crashed Chip as it don't allow background.
So I have to stop using ContextThemeWrapper , maybe I misunderstood real purpose, I wanted to apply style to my view programmatically, what actually worked, but it modified whole theme.
So I found library paris for aplying styles programatically and changed that code to:
view = FrameLayout(context()).apply style(R.style.CSNavigationContainer)
now it works with the same style.
edited Nov 13 at 23:02
answered Nov 13 at 18:39
Renetik
1,9482135
1,9482135
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247229%2fmaterial-android-chip-is-crashing-when-inflated-in-xml-layout%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What theme are you using for the activity that has this
Chip
in it? Does this theme defineandroid:background
?– Ben P.
Nov 12 at 22:21
@BenP. I added my theme file, nothing special there...
– Renetik
Nov 13 at 16:34
Where is the Chip located? Is it in the action bar?
– Ben P.
Nov 13 at 16:43