我试图在android studio中编写登录/注册程序,我在youtube上关注了本教程:https://www.youtube.com/watch?v=3RewvdB82PY 但我的应用程序一直在崩溃。
我的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)
答案 0 :(得分:1)
看看这一行
Caused by: java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
它告诉您,您正在尝试将TextInputEditText
类型的对象转换为TextInputLayout
。
现在,请看下一行:
at com.myiscaeproject.az.myapp.activities.MainLogIn.initViews(MainLogIn.java:54)
它告诉你,它发生在MainLogIn.java
文件的第54行。
学习阅读堆栈跟踪,它有很多帮助。
答案 1 :(得分:0)
如果您阅读了错误/异常,则可以看到java.lang.ClassCastException: android.support.design.widget.TextInputEditText cannot be cast to android.support.design.widget.TextInputLayout
我想在你的活动文件中你试图将TextInputEditText分配给TextInputLayout。请使用findViewById检查您分配的位置。