0

I have a FloatingActionMenu that has two FloatingActionButtons in it. I am trying to open a website when one of the buttons is clicked, but my app crashes when homePage runs.

Here is my java code:

public class homePage extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_page);

    final String website = "http://www.facebook.com/slgnalinprogrammer";
    FloatingActionButton fabWebsite = findViewById(R.id.fabWebsite);

    fabWebsite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(website));
            startActivity(i);
        }
    });
}

My layout XML:

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    app:fab_addButtonColorNormal="#008577"
    app:fab_addButtonColorPressed="#00574B"
    app:fab_addButtonPlusIconColor="#ffffff"
    app:fab_labelStyle="@style/custom_fab">
    <com.getbase.floatingactionbutton.FloatingActionButton
        android:onClick="openWebsite"
        android:id="@+id/fabWebsite"
        app:fab_title="Website"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fab_colorNormal="#008577"
        app:fab_addButtonColorPressed="#00574B"
        app:fab_icon="@drawable/websiteicon"
        app:fab_size="mini"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>

The stack trace from the crash:

java.lang.RuntimeException: Unable to start activity ComponentInfo{slgnalin.impladent/slgnalin.impladent.homePage}: java.lang.ClassCastException: com.getbase.floatingactionbutton.FloatingActionButton cannot be cast to android.support.design.widget.FloatingActionButton
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.ClassCastException: com.getbase.floatingactionbutton.FloatingActionButton cannot be cast to android.support.design.widget.FloatingActionButton
    at slgnalin.impladent.homePage.onCreate(homePage.java:23)
    at android.app.Activity.performCreate(Activity.java:7183)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Mike M.
  • 38,532
  • 8
  • 99
  • 95
slgnalin
  • 25
  • 6
  • Share your log first – Mitesh Vanaliya Dec 11 '18 at 14:52
  • My log can be found here: https://ufile.io/9j1jr – slgnalin Dec 11 '18 at 18:29
  • Those logs are not what we need. You're looking for [the stack trace from the crash](https://stackoverflow.com/q/23353173), which should be a large section of red lines, starting with `FATAL EXCEPTION`. You can use the filters above the log window to make it easier to find. – Mike M. Dec 11 '18 at 18:42
  • Also, please [edit] your question to add the stack trace here when you find it. Please don't link to it off-site. – Mike M. Dec 11 '18 at 18:51
  • Is this it? https://ufile.io/4swjk – slgnalin Dec 11 '18 at 18:51
  • Yes, that's it. You've got the wrong `FloatingActionButton` class imported in your `Activity`. It should be `import com.getbase.floatingactionbutton.FloatingActionButton;`. – Mike M. Dec 11 '18 at 18:54
  • Hey that was awesome! Also, could you add you suggestion as an answer so I could rate it as "solution" ? – slgnalin Dec 11 '18 at 18:56
  • If you would, please add that stack trace to your question. I'll see if Benjamin would like to correct their answer, so you could accept theirs, if you like, since they've already got one posted. I'd probably just mark this as a duplicate. Thank you, though. I appreciate the offer. Glad you got it working. Cheers! – Mike M. Dec 11 '18 at 19:07

1 Answers1

2

Your layout element is a com.getbase.floatingactionbutton.FloatingActionButton, but the stack trace shows that you're trying to cast it to android.support.design.widget.FloatingActionButton.

This would indicate that you've got the wrong FloatingActionButton class imported in your Activity. Your import statement should be:

import com.getbase.floatingactionbutton.FloatingActionButton;
Mike M.
  • 38,532
  • 8
  • 99
  • 95
Benjamin
  • 401
  • 1
  • 3
  • 16