Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException: androidx.appcompat.app.AppCompatDelegateImpl cannot be cast to gueei.binding.ViewFactory #14

Open
alexei-28 opened this issue Jul 8, 2019 · 1 comment

Comments

@alexei-28
Copy link

alexei-28 commented Jul 8, 2019

has custom bindable lib - https://github.com/gueei/AndroidBinding

package gueei.binding;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.LayoutInflater.Factory;
import java.util.ArrayList;

public class ViewFactory implements import android.view.LayoutInflater.Factory; {

}

Here my snippet:

import gueei.binding.Binder;
import gueei.binding.Binder.InflateResult;
import gueei.binding.ViewFactory;
import androidx.fragment.app.FragmentActivity;

LayoutInflater layoutInflater = LayoutInflater.from(context)
                .cloneInContext(context);
        LayoutInflater.Factory layoutInflaterFactory = layoutInflater
                .getFactory();
        ViewFactory bindingViewFactory = null;
        if (!(layoutInflaterFactory instanceof FragmentActivity)) {
            bindingViewFactory = (ViewFactory) layoutInflaterFactory;
        }
        if (bindingViewFactory == null) {
            bindingViewFactory = new ViewFactory(layoutInflater);
            layoutInflater.setFactory(bindingViewFactory);
}

And when I use android.support.v4.app.FragmentActivity my code work fine.

But now I upgrade android project to use androidx.appcompat.app.AppCompatActivity;

and as result in line:

bindingViewFactory = (ViewFactory) layoutInflaterFactory;
I has runtime error:

 FATAL EXCEPTION: main
 Process: com.myproject.tango.debug, PID: 10249
 java.lang.ClassCastException: androidx.appcompat.app.AppCompatDelegateImpl cannot be cast to gueei.binding.ViewFactory
    at com.myproject.binding.widget.BindableWidgetHelper.bindv4Fragment(BindableWidgetHelper.java:138)
    at com.myproject.commons.LayoutService.addView(LayoutService.java:128)
    at com.myproject.commons.LayoutService.addBody(LayoutService.java:150)
    at com.myproject.tango.widget.banner.BannerFragment.prepareChild(BannerFragment.java:211)
    at com.myproject.commons.roots.RootFragment.onCreateView(RootFragment.java:103)
    at com.myproject.tango.widget.banner.BannerFragment_.onCreateView(BannerFragment_.java:42)
    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2612)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:874)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1228)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1293)
@egandro
Copy link

egandro commented Jul 8, 2019

Sorry. This project is no longer maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants