java 我的应用程序一直在 android 模拟器中停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43694876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 07:39:46  来源:igfitidea点击:

my app keeps stopping in android emulator

javaandroidclasscastexception

提问by AyaX

i'm trying to code a login/register program in android studio , and i followed this tutorial on youtube : https://www.youtube.com/watch?v=3RewvdB82PYbut my app keeps crashing.

我正在尝试在 android studio 中编写登录/注册程序,我在 youtube 上遵循了本教程:https: //www.youtube.com/watch?v=3RewvdB82PY但我的应用程序不断崩溃。

my logcat looks like this:

我的 logcat 看起来像这样:

   04-29 00:01:58.833 10970-10970/com.myproject.az.myapp E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.myproject.az.myapp, PID: 10970
                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myiscaeproject.az.myapp/com.myiscaeproject.az.myapp.activities.MainLogIn}: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                             at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:154)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                          Caused by: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
                                                                             at com.myiscaeproject.az.myapp.activities.MainLogIn.initViews(MainLogIn.java:54)
                                                                             at com.myiscaeproject.az.myapp.activities.MainLogIn.onCreate(MainLogIn.java:46)
                                                                             at android.app.Activity.performCreate(Activity.java:6679)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)?
                                                                             at android.app.ActivityThread.-wrap12(ActivityThread.java)?
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)?
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)?
                                                                             at android.os.Looper.loop(Looper.java:154)?
                                                                             at android.app.ActivityThread.main(ActivityThread.java:6119)?
                                                                             at java.lang.reflect.Method.invoke(Native Method)?
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)?
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)?

回答by Henry

Look at this line

看看这条线

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

It tells you, you are trying to cast an object of type TextInputEditTextto a TextInputLayout.

它告诉您,您正在尝试将类型的对象强制TextInputEditText转换为TextInputLayout.

Now, look at the next line:

现在,看看下一行:

at com.myiscaeproject.az.myapp.activities.MainLogIn.initViews(MainLogIn.java:54)

it tells you, it happens in line 54 of your MainLogIn.javafile.

它告诉你,它发生在你MainLogIn.java文件的第 54 行。

Learn to read stack traces, it helps a lot.

学习阅读堆栈跟踪,它有很大帮助。

回答by N.Moudgil

If you read your error/exception you can see java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout

如果您阅读错误/异常,您可以看到 java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout

I guess in your activity file you are trying to assign TextInputEditText to TextInputLayout. Please check where you are assigning using findViewById.

我猜在您的活动文件中,您正试图将 TextInputEditText 分配给 TextInputLayout。请检查您使用 findViewById 分配的位置。