I have an Android library, LabelledSpinner
which is essentially a compound view that holds a Spinner
with TextView
s, all in a LinearLayout
.
However, when I run the app on Android 4 devices (my library supports Android 4 upwards), I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{MyActivity}: android.view.InflateException: Binary XML file line #98: Error inflating class com.farbod.labelledspinner.LabelledSpinner
...
Caused by: java.lang.NoSuchMethodError: android.widget.LinearLayout.<init>
at com.farbod.labelledspinner.LabelledSpinner.<init>(LabelledSpinner.java:117)
at com.farbod.labelledspinner.LabelledSpinner.<init>(LabelledSpinner.java:112)
at com.farbod.labelledspinner.LabelledSpinner.<init>(LabelledSpinner.java:108)
...
Users of my library encountered the same issue.
Here are my constructors (you can also view the entire file on the GitHub repository) - note that this file extends LinearLayout
:
public LabelledSpinner(Context context) {
this(context, null);
}
public LabelledSpinner(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public LabelledSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initializeLayout(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LabelledSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initializeLayout(context, attrs);
}
I think the error points specifically to the third constructor (the line references in the error aren't exactly clear to me).
I find it strange that I am given this error, as looking at the LinearLayout
class, the constructors I am using are available:
public LinearLayout(Context context) {...}
public LinearLayout(Context context, @Nullable AttributeSet attrs) {...}
public LinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {...}
public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
...
}
I am not getting this issue on Android Lollipop devices.
It turns out that in my case, my app was using an outdated version of the library (to be specific, I had not pushed the updates from my library to Bintray).
More information on the comment on the GitHub issue.