Java Gradle构建工具升级导致ClassCastException
我把格拉德尔从Java Gradle构建工具升级导致ClassCastException,java,android,gradle,android-gradle-plugin,Java,Android,Gradle,Android Gradle Plugin,我把格拉德尔从 classpath 'com.android.tools.build:gradle:2.3.3' 到 这导致了以下错误 java.lang.ClassCastException: 无法将android.support.design.widget.TextInputLayout强制转换为 android.support.design.widget.text输入文本 设置strPwd时会发生这种情况,但设置strUsername时不会发生这种情况 档案: <?xml vers
classpath 'com.android.tools.build:gradle:2.3.3'
到
这导致了以下错误
java.lang.ClassCastException:
无法将android.support.design.widget.TextInputLayout强制转换为
android.support.design.widget.text输入文本
设置strPwd时会发生这种情况,但设置strUsername时不会发生这种情况
档案:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="?android:colorBackground">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/section_spacer">
<include layout="@layout/layout_list_item_input"
android:id="@+id/username" />
<include layout="@layout/layout_list_item_input"
android:id="@+id/password" />
<include layout="@layout/spacer" />
<include layout="@layout/button_main"
android:id="@+id/btn_sign_in" />
<include layout="@layout/button_white"
android:id="@+id/btn_forgot_password" />
</LinearLayout>
</ScrollView>
为什么会发生此错误以及如何修复此错误。如果使用CompileSDK版本27,请添加以下内容:
implementation 'com.android.support:design:27.1.1'
您可能正在Java
findViewById
你应该用这样的东西
TextInputLayout TextInputLayout=(TextInputLayout)findViewById(R.id.TextInputLayout)代码>
用这个。也发布Java和XML。请将您的grandle文件添加到我想您可以在这里找到一些帮助:谢谢您的回复,我已经使用了设计库27.0.2版。@JanLindenberg如果您更新到最新的27.1.1版,您仍然会收到错误吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:focusable="true"
android:focusableInTouchMode="true">
<!-- Note: Separator is focusable to enable manually removing focus from edit views when needed.
Credit: https://stackoverflow.com/a/6118033/1291040
-->
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="?android:attr/listPreferredItemPaddingLeft">
<android.support.design.widget.TextInputEditText
android:id="@+id/input"
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionDone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical" />
</android.support.design.widget.TextInputLayout>
<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="?android:colorBackground" />
</LinearLayout>
final String strUsername = getListItemEditTextValue(username, INDEX_USERNAME);
final String strPwd = getListItemEditTextValue(password, INDEX_PASSWORD);
protected String getListItemEditTextValue(View view, int index) {
return ((TextInputEditText) view.findViewById(R.id.input + index)).getText().toString();
}
implementation 'com.android.support:design:27.1.1'