-2

What is this error I'm getting in a particular layout of my app?

I have a specific layout (MonthlyComputation) that crashes the app when I go to this layout..

11-15 21:39:03.105: ERROR/AndroidRuntime(1169): FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity      ComponentInfo{com.ZecRepublic.ITax/com.ZecRepublic.ITax.MonthlyComputation}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    at android.app.ActivityThread.access$600(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
    at com.ZecRepublic.ITax.MonthlyComputation.onCreate(MonthlyComputation.java:49)
    at android.app.Activity.performCreate(Activity.java:5008)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
    ... 11 more
4
  • Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText at com.ZecRepublic.ITax.MonthlyComputation.onCreate(MonthlyComputation.java:49) On line 49, you are trying to force a TextView to be an EditText.
    – Sam
    Jan 15, 2013 at 18:47
  • show the code and the xml layout please Jan 15, 2013 at 18:50
  • You really need to learn how to read a Logcat.. It usually always tells you the problem, and even the line it can be found on.
    – IAmGroot
    Jan 15, 2013 at 18:53
  • yes, I'm sorrryyy. I got it. Thanks for all of your answers! Jan 15, 2013 at 19:18

2 Answers 2

3

Simple. You're trying to cast a TextView to an EditText. Don't do that.

2
  • Sorry! :( Yeah I got it! Thanks! Jan 15, 2013 at 19:17
  • Don't be sorry. Do you know why you got this error and how you can find an solve this in the future?
    – nhaarman
    Jan 15, 2013 at 20:00
3

android.widget.TextView cannot be cast to android.widget.EditText

You are trying Typecast TextView to EditText.

 txtView = (EditText) findViewById(R.id.txtView1);

change to

 txtView = (TextView) findViewById(R.id.txtView1);

Hope its clear

1
  • Thank you, I really don't know how to read the logcat before. Jan 15, 2013 at 19:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.