gpt4 book ai didi

java - 将类型转换器与 Room 一起使用时出现 StackOverFlow 错误

转载 作者:行者123 更新时间:2023-12-02 11:00:49 25 4
gpt4 key购买 nike

我正在与 TheMovieDatabase API 交互,发现 here .

我正在尝试提取流行度字段,该字段的对象类型为Number

Room 需要一个用于该对象的类型转换器,我已将其集成在下面:

public class NumberConverter {

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


@TypeConverter
public static Integer toInt(Number number){
return number == null ? null : number.intValue();
}


}

当我加载应用程序时,我立即收到引用此行的 StackOverFlow 错误:

        return number == null ? null : number.intValue();

注意:我还使用 Executors 来异步处理读写:

public class AppExecutors{

//for Singleton Instantiation
private 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);
}
}



}

编辑:引用TheMovieDatabase文档

最佳答案

你能在你的代码中检查一下这个函数吗:

@TypeConverter
公共(public)静态数字toNumber(整数整数){
返回整数 == null ? null : toNumber(整数); }

这里发生了无限的递归,也许这就是您收到StackOverflowError的原因。

关于java - 将类型转换器与 Room 一起使用时出现 StackOverFlow 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51341668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com