美文网首页
Lottie异常

Lottie异常

作者: 真胖大海 | 来源:发表于2019-12-04 15:37 被阅读0次

Lottie版本 2.6.0

一.异常

java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Path$FillType.nativeInt' on a null object reference

二.原因

解析Lottie的json文件时,关于渐变的字段中没有"r",导致fillType为空

FillType

三.解决方法

3.1 方法一

更新Lottie到3.3.0因为3.3.3给FillType设置了默认值

    Path.FillType fillType = Path.FillType.WINDING

但是升级到Lottie3.3.0的话,要注意,3.3.0依赖的是androidx包,如果整个工程如果原来依赖的是android support包,就要改为依赖androidx包

3.2 方法二

下载2.6.0 的代码给fillType设置默认值

3.3 方法三

使用切面编程,如果检测到fillType为空,则给FillType设置值

 @Around("execution(com.airbnb.lottie.model.content.GradientFill.new(..))")
    public Object checkGradientFill(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Log.i("checkGradientFill","---------------------");
        Object[] args = proceedingJoinPoint.getArgs();
        for(Object object:args){
            Log.i("checkGradientFill",object+"");
        }
        if(args[2]==null){
            args[2]= Path.FillType.EVEN_ODD;
        }
        return proceedingJoinPoint.proceed(args);
    }

相关文章

网友评论

      本文标题:Lottie异常

      本文链接:https://www.haomeiwen.com/subject/follgctx.html