引起:java.lang.ClassCastException:android.widget.FrameLayout无法强制转换为com.appeaser.sublimepickerlibrary.S

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了引起:java.lang.ClassCastException:android.widget.FrameLayout无法强制转换为com.appeaser.sublimepickerlibrary.S相关的知识,希望对你有一定的参考价值。

我试图在FrameLayout内加载片段,但得到以下异常/崩溃

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:title="@string/app_name"
            app:titleTextColor="@color/white"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <com.appeaser.sublimepickerlibrary.SublimePicker
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appBarLayout"
        android:layout_above="@+id/bottom_navigation" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_CreateEvent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="@dimen/fab_margin_right"
        android:clickable="true"
        android:src="@drawable/plus"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:backgroundTint="@color/colorPrimary"
        app:rippleColor="@color/colorPrimaryDark" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/bottom_navigation_main" />

</RelativeLayout>

main activity.Java

FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        DatePickerFragment datePickerFragment = new DatePickerFragment();
        fragmentTransaction.replace(R.id.content_frame, datePickerFragment);
        fragmentTransaction.commit();

错误日志

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appeaser.sublimepicker/com.appeaser.sublimepicker.MainActivity}: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to com.appeaser.sublimepickerlibrary.SublimePicker
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                  at android.os.Looper.loop(Looper.java:164)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                               Caused by: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to com.appeaser.sublimepickerlibrary.SublimePicker
                                                                                  at com.appeaser.sublimepicker.DatePickerFragment.onCreateView(DatePickerFragment.java:102)
                                                                                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                                  at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                                  at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                                  at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                                  at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                                  at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                                  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                                  at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                                  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
                                                                                  at android.app.Activity.performStart(Activity.java:6992)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                                  at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                                  at android.os.Looper.loop(Looper.java:164) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

此外,我在我的应用程序中自定义库库代码下面。

https://github.com/vikramkakkar/SublimePicker

请帮我。

答案

将Framelayout更改为

<com.appeaser.sublimepickerlibrary.SublimePicker
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appBarLayout"
        android:layout_above="@+id/bottom_navigation" />

以上是关于引起:java.lang.ClassCastException:android.widget.FrameLayout无法强制转换为com.appeaser.sublimepickerlibrary.S的主要内容,如果未能解决你的问题,请参考以下文章

查询如何引起gc

杂牌设备网络接入引起交换机引起端口翻转的故障

csharp 可能会引起问题的类的继承问题,父类后来增加的方法可能会引起子类的函数重载错误

两则dhcp设置引起的故障

大开测试:性能-如何解决由于设置引起的运行失败问题(连载22)

查找由智能指针引起的内存泄漏