gueei.binding:java.lang.ClassCastException:androidx.appcompat.app.AppCompatDelegateImpl无法转换为gueei.binding.ViewFactory

时间:2019-07-08 16:34:23

标签: binding androidx

我具有自定义可绑定库-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; {

}

这是我的摘录:

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);
}

当我使用android.support.v4.app.FragmentActivity时,我的代码可以正常工作。

但是现在我将android项目升级为使用androidx.appcompat.app.AppCompatActivity;

,结果如下:

bindingViewFactory = (ViewFactory) layoutInflaterFactory;

我遇到运行时错误:

 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)

0 个答案:

没有答案