-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
  • `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 '13 at 18:47
  • show the code and the xml layout please – mikeswright49 Jan 15 '13 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 '13 at 18:53
  • yes, I'm sorrryyy. I got it. Thanks for all of your answers! – Karla Mae Z. Jaro Jan 15 '13 at 19:18

2 Answers2

3

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

nhaarman
  • 98,571
  • 55
  • 246
  • 278
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

Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31