#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    1
    Rep Power
    0

    Keep having error! New to app development


    Hi was just wondering if anyone here is able to help me. I am making an app and have just created a new activity and am trying to load that activity when I click on a ImageButton. I thought I had done it correctly but I am now getting a crash every time i go to run the app.

    Does this error message make sense to anyone? Would really appreciate some help! Thank you

    Code:
    09-19 17:31:19.238 2625-2625/com.dan.fletcher.golearnthai E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.dan.fletcher.golearnthai, PID: 2625
                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dan.fletcher.golearnthai/com.dan.fletcher.golearnthai.MainActivity}: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageButton cannot be cast to android.widget.Button
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
                                                                                    at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:158)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                                 Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageButton cannot be cast to android.widget.Button
                                                                                    at com.dan.fletcher.golearnthai.MainActivity.onCreate(MainActivity.java:18)
                                                                                    at android.app.Activity.performCreate(Activity.java:6876)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
                                                                                    at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:158)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2016
    Posts
    2
    Rep Power
    0
    You are trying to cast AppCompatImageButton to button. First decide if you want to support old versions of the Android OS that is what appcompat means compatibility with older versions. Image buttons have an image buttons have text. Now the issue you have is line 18 main activity change the word button to ImageButton or AppCompatImageButton. If line 18 does not have the word Button then you declared the varable on some other line, thats ok find the variable on line 18 mainactivity where that variable is declared make it AppCompatImageButton or ImageButton. If you post the code and error log that would help if my solution does not work for you. Good luck

IMN logo majestic logo threadwatch logo seochat tools logo