【问题标题】:"The following classes could not be found" with custom Kotlin view in layout在布局中使用自定义 Kotlin 视图“找不到以下类”
【发布时间】:2017-08-27 20:27:39
【问题描述】:

我遇到了一个问题,包括 XML 布局文件中的自定义 Kotlin 视图。代码如下:

class CustomView: RelativeLayout {

    /**
     * Programmatic constructor
     */
    constructor(aVariable: Boolean, context: Context): super(context) { ... }

    /**
     * XML constructor
     */
    @JvmOverloads
    constructor(context: Context, attributeSet: AttributeSet? = null, defStyle: Int = 0): super(context, attributeSet, defStyle) { ... }

}

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.turingtechnologies.materialscrollbar.CustomView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

然后布局预览器报错:

“缺课-

找不到以下类: com.turingtechnologies.materialscrollbar.CustomView(修复构建路径,编辑 XML,创建类)"

注意:这是 AS 3.0 beta 3

【问题讨论】:

  • 稳定的 AS 版本的行为是什么?
  • @MaximOstrovidov 我会看看并告诉你
  • 代码看起来不错。可能只是 AS 的一些滞后。尝试“清理 -> 重建”或使缓存无效。
  • @GeorgySavatkov 我都做过

标签: android android-studio kotlin android-custom-view


【解决方案1】:

确认错误https://issuetracker.google.com/issues/62255811。修复应该会出现在 Android Studio 的下一个版本中。

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 2012-07-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多