【问题标题】:Custom/compound view: NoSuchMethodError for LinearLayout constructor自定义/复合视图:LinearLayout 构造函数的 NoSuchMethodError
【发布时间】:2016-07-02 19:24:27
【问题描述】:

我有一个 Android 库,LabelledSpinner,它本质上是一个复合视图,其中包含 SpinnerTextViews,都在 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)——注意这个文件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 设备上没有遇到此问题。

【问题讨论】:

  • 尝试使用同一库的一个先前版本。 github.com/FarbodSalamat-Zadeh/LabelledSpinner/releases,这写在您问题中链接的最后一个答案中。
  • @vabhivab 你到底是什么意思?如果您的意思是使用该库的早期版本,我知道这一点,但我制作了该库,因此我正在尝试找到解决此问题的方法。

标签: android constructor android-linearlayout android-custom-view android-compound-view


【解决方案1】:

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

更多信息on the comment on the GitHub issue

【讨论】:

    猜你喜欢
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2014-01-07
    • 2012-05-22
    相关资源
    最近更新 更多