TextInputEditText 无法转换为 TextInputLayout

2024-01-09

我的活动中有此代码

public class RegisterActivity extends AppCompatActivity {


private static final String TAG = RegisterActivity.class.getSimpleName();
private TextInputLayout mDisplayName;
private TextInputLayout mEmail;
private TextInputLayout mPassword;
private Button mCreateBtn;

private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    mAuth = FirebaseAuth.getInstance();

    mDisplayName = (TextInputLayout)findViewById(R.id.reg_display_name);
    mEmail = (TextInputLayout)findViewById(R.id.reg_email);
    mPassword = (TextInputLayout)findViewById(R.id.reg_password);
    mCreateBtn = (Button) findViewById(R.id.reg_create_btn);

    mCreateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String displayName = mDisplayName.getEditText().getText().toString();
            String email = mEmail.getEditText().getText().toString();
            String password = mPassword.getEditText().getText().toString();

            registerUser(displayName,email,password);

        }


    });
}

private void registerUser(String displayName, String email, String password) {

   mAuth.signInWithEmailAndPassword(email,password)
           .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
               @Override
               public void onComplete(@NonNull Task<AuthResult> task) {
                     if(task.isSuccessful()){
                         Intent mainIntent = new Intent(RegisterActivity.this,MainActivity.class);
                         startActivity(mainIntent);
                         finish();
                     }else{
                         Toast.makeText(RegisterActivity.this,"You got some error.",Toast.LENGTH_SHORT).show();
                     }
               }
           });

}


}

其对应的XML代码为:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RegisterActivity">
    
    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout2"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        
        <android.support.design.widget.TextInputEditText
            android:id="@+id/reg_display_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint"
            android:text="Display name" />
    </android.support.design.widget.TextInputLayout>
    
    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout3"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout2">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/reg_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint"
            android:text="Email" />
    </android.support.design.widget.TextInputLayout>
    
    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout4"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout3">
    
        <android.support.design.widget.TextInputEditText
            android:id="@+id/reg_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint"
            android:text="Password" />
    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/reg_create_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Create account"
        android:textAllCaps="false"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout4"
        tools:layout_editor_absoluteX="255dp" />
</android.support.constraint.ConstraintLayout>

当我运行该应用程序时,我收到以下消息:

Caused by: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout

我还给您提供了 gradle 文件,以防设计版本出现问题。

 apply plugin: 'com.android.application'

 android {
 compileSdkVersion 27
 defaultConfig {
    applicationId "theo.tziomakas.lapitchat"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
  }
   buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
   }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint- 
layout:1.1.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 
'com.android.support.test.espresso:espresso-core:3.0.2'
 }

 apply plugin: 'com.google.gms.google-services'

那么有什么想法可以解决这个异常吗?

谢谢 西奥.


尝试转换为

private TextInputEditText mDisplayName;
private TextInputEditText mEmail;
private TextInputEditText mPassword;


mDisplayName = (TextInputEditText)findViewById(R.id.reg_display_name);
mEmail = (TextInputEditText)findViewById(R.id.reg_email);
mPassword = (TextInputEditText)findViewById(R.id.reg_password);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TextInputEditText 无法转换为 TextInputLayout 的相关文章

随机推荐

  • 如何使用boto3通过s3上的url访问图像?

    我想要完成的是生成一个链接来查看文件 例如图像或pdf 该项目无法通过 URL 访问 https 存储桶 s3 amazonaws com img name jpg https 5Bbucket 5D s3 amazonaws com im
  • getItemAtPosition() 如何从 ListView 中的选定项获取可读数据

    我有一个从 Android ContactManager 示例中获取的联系人列表视图 该列表显示正常 但我不知道如何从所选项目中获取信息 例如 姓名 和 电话号码 我可以获得选定的位置 但 mContactList getItemAtPos
  • 当我们只更新一个属性时,我们应该使用强参数吗?

    我正在开发一个 Rails 应用程序 我有几个操作 delete later ban later 等 其中我只从请求参数中设置一个属性 具体来说 reason执行该操作的字段 我想知道这样做是否可以 def ban later object
  • 转换数据库中嵌入的图片

    我有一个 小 问题 在数据库文档中包含富文本字段 富文本字段包含某个联系人的个人资料图片 问题是这个内容没有保存为 mime 因此我无法计算图像的 url 我正在使用 pojo 从人员配置文件中检索数据 并在我的 xpage 控件中使用它来
  • 编写正则表达式来检测重复字符[重复]

    这个问题在这里已经有答案了 我需要编写一个正则表达式 它可以识别一个具有重复字符集 at the end 根据以下代码片段 重复字符集为An 我需要编写一个正则表达式 以便能够发现并显示它 根据下面的代码 w将匹配任何单词字符 包括数字 字
  • 如何将 Bower 用作 Visual Studio 2013 的包管理器? IE。我有一个 .NET 项目,想要添加一些使用 Bower 的包

    如何将 Bower 用作 Visual Studio 2013 的包管理器 IE 我有一个 NET 项目 想要添加一些使用 Bower 的包 I read 斯科特 汉塞尔曼的帖子 http www hanselman com blog In
  • 数据表添加到数据集

    我需要为数据集设置一个表 DataSet ds EventDal GetEvents DataSet dsReturn new DataSet DataTable dtReturn dsReturn Tables Add dtReturn
  • 子域 Azure WebApp

    这是一个更普遍的问题 我有一个作为 Azure 应用服务运行的网站 我配置了一个自定义域 以便您可以通过以下方式调用它我的网站名称 com 随着客户的要求不断增长 每个客户都有特定的需求 我想知道是否可以为每个客户拥有一个子域 例如 cli
  • pandas + pyodbc ODBC SQL 类型 -150 尚不支持

    我知道这方面有很多主题 但我认为这是非常具体的 我得到用于审计目的的当前代码 import pandas as pd import pyodbc query Top 50 high total CPU Queries SELECT TOP
  • 在 nginx 上为应用程序添加上下文路径

    Nginx 负责从根目录到根 URL 的所有静态内容 例如 如果根内容位置配置为 usr share nginx html其中包含一个文件 usr share nginx html foo html 然后是网址http localhost
  • Zope 冲突错误

    我的网站的 zope 日志报告了许多冲突错误 平均每天120个 其中2 3个未解决 我读过很多关于为什么会发生冲突错误的文章 但没有什么是清楚的 大多数冲突错误发生在对 MySQL 数据库运行选择查询的页面上 据称 随着 http 请求并发
  • 开始 Lua 脚本编写 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我正处于被迫学习Lua的阶段 所以你对我如何做到这一点有什么建议吗 除了 PHP 之外 我对其他脚本语言没有太多经验 那么 关于 head
  • django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。 (django 2.0.1)(Python 3.6)

    这是我第一次尝试将 Django 应用程序 django 2 0 1 Python 3 6 部署到 pythonanywhere 它是一个简单的组合应用程序 没有模型 没有引导程序 只需 Django HTML CSS 和 JavaScri
  • 将 prop 传递给样式组件

    我正在尝试找到一种方法来动态创建 居中此 div 组件 这段代码目前可以工作 但有点冗长而且不是很干 const Rel styled div position relative height 100 width 100 const Abs
  • iOS:根据加速度计输出准确确定碰撞能量

    我正在创建一个音叉应用程序 您可以将 iPhone 轻拍到另一只手的手掌上 或者轻拍到柔软的表面上 以设置音叉的声音 所以我想检测每个 凹凸 中包含的能量 编辑 删除了大量的gumpf 谁能帮我破解这个吗 感谢 freenode 的 mat
  • Python 中与 finditer() 的重叠匹配

    我正在使用正则表达式来匹配文本中的圣经经文引用 当前的正则表达式是 REF REGEX re compile q uote s Match optional q or quote followed by many spaces P
  • 如何在 iOS 和 Android 应用程序的 React Native 中禁用字体缩放?

    设备字体大小的放大有时会中断 样式方面 禁用字体缩放可能会损害应用程序的可访问性 理想情况下 如果您想限制使用 React Native 0 58 0 及更高版本的应用程序的缩放 使用maxFontSizeMultiplier prop h
  • HTTP 请求被视为超时的默认时间是多少?

    对于 PHP HTTP 请求被视为超时的默认时间是多少 我正在使用 PECL HTTP 扩展来发出 HTTP 请求 我可以在发出请求时设置超时限制 但是我想知道如果没有明确指定任何内容 默认值是什么 我查遍了 PHP 手册 但没有结果 我希
  • 在android中以编程方式创建vCard文件

    我使用以下代码来读取联系人并创建 vcard 文件 String lookupKey cur getString cur getColumnIndex Contacts LOOKUP KEY Uri uri Uri withAppended
  • TextInputEditText 无法转换为 TextInputLayout

    我的活动中有此代码 public class RegisterActivity extends AppCompatActivity private static final String TAG RegisterActivity class