medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

Caused by: java.lang.ClassCastException: mehdi.sakout.fancybuttons.FancyButton cannot be cast to android.widget.Button #32

Closed maxime-kouemo closed 9 years ago

maxime-kouemo commented 9 years ago

This is my log. I added two buttons and tried to tie it to and activity.

Process: com.example.max_poly.driverecord, PID: 1553 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.max_poly.driverecord/com.example.max_poly.driverecord.MenuActivity}: java.lang.ClassCastException: mehdi.sakout.fancybuttons.FancyButton cannot be cast to android.widget.Button at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: mehdi.sakout.fancybuttons.FancyButton cannot be cast to android.widget.Button at com.example.max_poly.driverecord.MenuActivity.onCreate(MenuActivity.java:20) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)             at android.app.ActivityThread.access$800(ActivityThread.java:135)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:136)             at android.app.ActivityThread.main(ActivityThread.java:5017)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:515)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)             at dalvik.system.NativeStart.main(Native Method)

layout code: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fancy="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">

<mehdi.sakout.fancybuttons.FancyButton
    android:id="@+id/btn_recordPath"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp"
    fancy:fb_borderColor="#FFFFFF"
    fancy:fb_borderWidth="1dp"
    fancy:fb_defaultColor="#7ab800"
    fancy:fb_focusColor="#9bd823"
    fancy:fb_fontIconResource="&#xf041;"
    fancy:fb_iconPosition="left"
    fancy:fb_radius="100dp"
    fancy:fb_text="Record your Path"
    fancy:fb_textSize = "15dp"
    fancy:fb_fontIconSize = "15dp"
    fancy:fb_textColor="#FFFFFF"
    android:layout_gravity="center_horizontal" />

<mehdi.sakout.fancybuttons.FancyButton
    android:id="@+id/btn_history"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp"
    fancy:fb_borderColor="#FFFFFF"
    fancy:fb_borderWidth="1dp"
    fancy:fb_defaultColor="#7ab800"
    fancy:fb_focusColor="#9bd823"
    fancy:fb_fontIconResource="&#xf1da;"
    fancy:fb_iconPosition="left"
    fancy:fb_radius="100dp"
    fancy:fb_text="History"
    fancy:fb_textSize = "15dp"
    fancy:fb_fontIconSize = "15dp"
    fancy:fb_textColor="#FFFFFF"
    android:layout_gravity="center_horizontal" />

activity code: public class MenuActivity extends Activity { private Button btRecordPath; private Button btHistory;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.menu_activity);

/**/ btRecordPath_ = (Button)findViewById(R.id.btnrecordPath); // btHistory = (Button) findViewById(R.id.btn_history);

    btRecordPath_.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(MenuActivity.this, MapActivitySecond.class);
            MenuActivity.this.startActivity(myIntent);
        }
    });
}

}

the logcat points the line 20 which is where I put the /**/

                       *
                     *   *

Edit:

Well I solved the problem. 1- In my activity I should have declared the buttons as FancyButton instead of Button 2- In my androidManifest I should have registered my activity by adding <activity android:name=".MapActivitySecond" android:configChanges="orientation|screenSize"/> under the main activity in the application tag. Very easy going library, thanks again

medyo commented 9 years ago

Solved !