为了账号安全,请及时绑定邮箱和手机立即绑定

与房间一起使用类型转换器时的StackOverFlow错误

与房间一起使用类型转换器时的StackOverFlow错误

LEATH 2021-05-13 14:06:43
我正在尝试拉动对象类型的Popularity字段Number。Room需要此对象的类型转换器,我在下面进行了集成:public class NumberConverter {@TypeConverterpublic static Number toNumber(Integer integer){    return integer == null ? null : toNumber(integer); }@TypeConverterpublic static Integer toInt(Number number){    return number == null ? null : number.intValue();  }}加载应用程序时,我立即收到引用以下行的StackOverFlow错误:        return number == null ? null : number.intValue();注意:我还Executors用于异步处理读写:public class AppExecutors{//for Singleton Instantiationprivate static final Object LOCK = new Object();private static AppExecutors sInstance;private final Executor diskIO;private final Executor mainThread;private final Executor networkIO;public AppExecutors(Executor diskIO, Executor mainThread, Executor networkIO) {    this.diskIO = diskIO;    this.mainThread = mainThread;    this.networkIO = networkIO;}public static AppExecutors getsInstance(){    if (sInstance == null){        synchronized (LOCK){            sInstance = new AppExecutors(Executors.newSingleThreadExecutor(),                    Executors.newFixedThreadPool(3),                    new MainThreadExecutor());        }    }    return sInstance;};public Executor diskIO(){return diskIO;};public Executor mainThread(){return mainThread;}public Executor netWorkIO(){return networkIO;}private static class MainThreadExecutor implements Executor{    private android.os.Handler mainThreadHandler = new android.os.Handler(Looper.getMainLooper());    @Override    public void execute(@NonNull Runnable runnable) {        mainThreadHandler.post(runnable);    }   }}
查看完整描述

1 回答

?
慕姐4208626

TA贡献1852条经验 获得超7个赞

您能否在代码中检查此功能:

@TypeConverter public static Number toNumber(Integer integer){    return integer == null ? null : toNumber(integer); }

recursion在这里无限进行,也许这就是为什么要获得的原因StackOverflowError


查看完整回答
反对 回复 2021-05-26
  • 1 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信