Null pointer appears for rxjava nested network access

the text in the diagram needs to be identified through ocr in the project, and the third-party ocr library is referenced, but there is a problem in the nesting of rxjava, and the key part of the code is pasted

.
Disposable disposable = Observable.just(OCR())
                        .observeOn(AndroidSchedulers.MainThread())
                        .subscribeOn(schedulers.newThread())
                        .flatMap(new Function<Rsult,ItemsBean>(){
                            ............
                        })
                        .subscribe(new Consumer(){
                            ............
                        })

where the ocr method itself is accessed through the network and returns the Request instance, probably posting the code of the ocr method

public static Result OCR(){
    ImageClient imageClient = new ImageClient();
    String result = imageClient.OCR(**,**,**);//
    Result resultEntity = gson.fromJson(result);
    return resultEntity;
}

after running, it is found that the result instance obtained in flatMap is empty, and then part of the code is changed to something like this

.
Disposable disposable = Observable.just(imageClient.OCR(**,**,**))
                        .observeOn(AndroidSchedulers.MainThread())
                        .subscribeOn(schedulers.newThread())
                        .map(new Function(){
                            ............
                        })
                        .flatMap(new Function<Rsult,ItemsBean>(){
                            ............
                        })
                        .subscribe(new Consumer(){
                            ............
                        })

then report network access in the main thread, what is the reason for this, and how to do this similar combination of network access nesting and rxjava?

Apr.22,2021

there is something wrong with the order of observeOn and subscribeOn


the data itself comes from the OCR method, the OCR method accesses the network, and the just sends the data immediately, which leads to the problem of empty data and network access in the main thread. The solution is as follows:

Disposable disposable = Observable.fromCallable(
            @Override
                public Object call(){
                    return .....
                })
                        .observeOn(AndroidSchedulers.MainThread())
                        .subscribeOn(schedulers.newThread())
                        .flatMap(new Function<Rsult,ItemsBean>(){
                            ............
                        })
                        .subscribe(new Consumer(){
                            ............
                        })

can solve the problem

Menu