gpt4 book ai didi

android - 自定义/复合 View : NoSuchMethodError for LinearLayout constructor

转载 作者:行者123 更新时间:2023-11-30 01:28:50 26 4
gpt4 key购买 nike

我有一个 Android 库,LabelledSpinner它本质上是一个复合 View ,包含一个 SpinnerTextView,所有这些都在一个 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)
...

我图书馆的用户遇到了the same issue .

这是我的构造函数(您还可以查看整个文件 on the GitHub repository )- 请注意,此文件扩展了 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 设备上没有遇到这个问题。

最佳答案

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

更多信息 on the comment on the GitHub issue .

关于android - 自定义/复合 View : NoSuchMethodError for LinearLayout constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com