1

我有一个 Android 库,LabelledSpinner它本质上是一个包含 aSpinnerTextViews 的复合视图,所有这些都在 a 中LinearLayout

但是,当我在 Android 4 设备上运行该应用程序(我的库支持 Android 4 以上)时,我收到以下错误:

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)
...

我的图书馆的用户遇到了同样的问题

这是我的构造函数(您也可以在 GitHub 存储库上查看整个文件) - 请注意此文件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);
}

我认为错误专门指向第三个构造函数(错误中的行引用对我来说并不完全清楚)。

我发现这个错误很奇怪,因为在查看LinearLayout类时,我正在使用的构造函数是可用的:

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) {
    ...
}

我在 Android Lollipop 设备上没有遇到这个问题。

4

1 回答 1

1

事实证明,在我的情况下,我的应用程序使用了一个过时版本的库(具体来说,我没有将更新从我的库推送到 Bintray)。

有关GitHub 问题的评论的更多信息。

于 2016-03-17T14:32:15.007 回答