ChonBon
ChonBon

Reputation: 11

App Crashes after moving an image button! android

So my app Ive been developing lately is going great, and I just updated the image in the background of the app. Well the app was working right before I tweaked an image button to line up with this image I made. Right after I moved it, the app will no longer work and I have tried everything with no success. Here is the xml of the activity

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/title_screen"
  tools:context=".TitleScreen" >

  <TextView
    android:id="@+id/txtCoins"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="18dp"
    android:layout_marginTop="11dp"
    android:text="000"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#f3c50d"
    android:textSize="12sp" />

  <ImageButton
    android:id="@+id/imageBtnPlay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txtCoins"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="51dp"
    android:background="@null"
    android:src="@drawable/btn_play" />

   </RelativeLayout>

EDIT: Here is my logcat

03-20 17:08:29.847: W/dalvikvm(28692): threadid=1: thread exiting with uncaught exception (group=0x416282a0)
03-20 17:08:29.852: E/AndroidRuntime(28692): FATAL EXCEPTION: main
03-20 17:08:29.852: E/AndroidRuntime(28692): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ChonBonStudios.Tidbits/com.ChonBonStudios.Tidbits.TitleScreen}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.os.Looper.loop(Looper.java:137)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread.main(ActivityThread.java:4898)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at java.lang.reflect.Method.invokeNative(Native Method)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at java.lang.reflect.Method.invoke(Method.java:511)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at dalvik.system.NativeStart.main(Native Method)
03-20 17:08:29.852: E/AndroidRuntime(28692): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton
03-20 17:08:29.852: E/AndroidRuntime(28692):    at com.ChonBonStudios.Tidbits.TitleScreen.onCreate(TitleScreen.java:20)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.Activity.performCreate(Activity.java:5191)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-20 17:08:29.852: E/AndroidRuntime(28692):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-20 17:08:29.852: E/AndroidRuntime(28692):    ... 11 more

Upvotes: 0

Views: 732

Answers (3)

Maik
Maik

Reputation: 3539

If I understand you correctly you just have switched the position of the TextView and the ImageButton in the layout, no code changes.

Try to simply clean the project and/or restart Eclipse. Sometimes I had a similar problem where the auto-generated Ids were just ouf of sync and that's the reason why a findViewById(R.id.imageBtnPlay) actually returns the TextView.

Upvotes: 0

Droidman
Droidman

Reputation: 11608

this is a common issue. Clean your project by selecting Project - Clean and it will work. And like gpasci said, check if you initialize your fields correctly

Upvotes: 0

gpasci
gpasci

Reputation: 1440

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

You are casting to the wrong class in your activity change TextView to ImageButton somewhere in com.ChonBonStudios.Tidbits.TitleScreen class.

Upvotes: 2

Related Questions