2013-03-20 66 views
0

所以我最近開發的應用程序進行得非常好,我只是在應用程序的後臺更新了圖像。那麼在我調整一個圖像按鈕來排列我製作的這個圖像之前,該應用程序正在工作。在我移動它之後,該應用程序將不再工作,並且我嘗試了一切都沒有成功。下面是活動移動圖像按鈕後,應用程序崩潰! android

<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> 

編輯的XML:這是我的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 
+1

顯示您的堆棧跟蹤... – 2013-03-20 21:04:55

回答

1

android.widget.TextView不能轉換到android.widget.ImageButton

你在你的活動中改變了TextViewImageButton類別com.ChonBonStudios.Tidbits.TitleScreen類別中的錯誤類別。

0

這是一個常見問題。通過選擇Project - Clean來清理您的項目,它將起作用。並且像gpasci說,檢查您是否正確初始化您的字段

0

如果我正確理解您,您只需切換佈局中的TextView和ImageButton的位置,不會更改代碼。

嘗試簡單地清理項目和/或重新啓動Eclipse。有時候我遇到類似的問題,自動生成的Ids僅僅是同步的,這就是爲什麼findViewById(R.id.imageBtnPlay)實際返回TextView的原因。

相關問題