kotlin - java.lang.ClassCastException:java.lang.Integer 无法转换为 android.widget.LinearLayout 当我尝试充气时
问题描述
rerferf我正在尝试在 Kotlin https://www.youtube.com/watch?v=hfoXhiMTc0c中复制本教程, 但是当我制作膨胀部分时出现此错误:
java.lang.ClassCastException:java.lang.Integer 无法转换为 android.widget.LinearLayout
这是我的代码
var bottomSheetDialog = BottomSheetDialog(this, R.style.Theme_Design_BottomSheetDialog) var view: View = LayoutInflater.from(application).inflate(R.layout.recover_password_sheet, R.id.sheet_container as LinearLayout)
custom_bottom_sheet.xml
xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/colorWhite"/> <corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/> </shape>
恢复密码表.xml
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sheet_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_bottom_sheet"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dp"
android:text="@string/forgot_password"
android:textColor="@color/colorBlack"
android:textStyle="bold"/>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhiteDivider"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/forgot_password_description"
android:padding="20dp"
android:gravity="start"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email"
android:layout_marginStart="24dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/txt_email"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/custom_rounded_login_text_view"
android:drawableLeft="@drawable/icon_username"
android:drawablePadding="10dp"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:paddingLeft="20dp"
android:paddingRight="20dp" />
</com.google.android.material.textfield.TextInputLayout>
<view
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhiteDivider"
android:paddingTop="20dp" />
<Button
android:id="@+id/btn_accept"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="@drawable/custom_rounded_corner_icons"
android:textColor="@color/colorWhite"
android:padding="20dp"
android:gravity="start"
android:textSize="15sp"
android:text="@string/accept"
android:textAlignment="center"
tools:ignore="RtlCompat" />
解决方案
您的问题在于:
R.id.sheet_container as LinearLayout
在那里,您尝试将整数(代表资源)转换为LinearLayout
.
查看LayoutInflater上的文档,找出函数的哪些重载inflate
更适合您的需求。
推荐阅读
- c++ - 变量只能全局“声明”,不能修改/(单独初始化)
- c# - 使用带有 x509 证书的 IIS 托管 WCF 服务进行身份验证
- python - 如何在 Python 中为 Google Analytics Reporting API(REST 方法)获取 oauth2-token
- angular - 无法绑定到“主题”,因为它不是“jqxTree”的已知属性
- c++ - C++ 应用程序:清除命令行参数?
- javascript - php 数据库到 javascript 图表
- angular - 带有 HashRouter 的子路径上的 Angular 6 无法加载图像资产
- asp.net-core - 在 ASP.Net Core 2.0 MVC 的控制器中未捕获查看数据期间。我是 ASP.Net 核心 MVC 的新手
- c# - 使用 Windows 服务在 FileSystemEventHandler 上插入数据库
- mysql - 在历史表中搜索时间戳中的一行,太慢了