Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

How can I make connection between retrofit and RxJava in different classes?

I have some classes as presenter and in these classes I use retrofit for some methods. But some methods are duplicated. So I want to use a class for all retrofit and connect to server methods and call them when I want. But when I created that class it has NullpointerException Error

I will be very thankful if you help me

this is presenter codes


public class DefinitionPresenter implements DefinitionContract.Presenter {
    private KalaBeanDataSource kalaBeanDataSource;
    private DefinitionContract.View view;
    private CompositeDisposable compositeDisposable = new CompositeDisposable();
    private DatabaseMethods databaseMethods;
    private ActivityKindList activityKindList;

    public DefinitionPresenter(KalaBeanDataSource kalaBeanDataSource){
        this.kalaBeanDataSource = kalaBeanDataSource;
databaseMethods = new DatabaseMethods(kalaBeanDataSource,compositeDisposable);
= new ActivityKindList(); } @Override public void attachView(DefinitionContract.View view) { this.view = view; } @Override public void detachView() {
= null; if(compositeDisposable != null && compositeDisposable.size() > 0){
.clear(); } } @Override public void activityKind() {
= databaseMethods.getActivityKind(); if(activityKindList.getItems().size() > 0){
.getActivityKind(activityKindList); }else{
.showMessage(databaseMethods.message); } } }


And this is a class that I created for get data from server with retrofit and RxJava


public  class DatabaseMethods {
    private KalaBeanDataSource kalaBeanDataSource;
    private CompositeDisposable compositeDisposable;
    private ActivityKindList activityKindListResult;
    public String message = null;

    public  DatabaseMethods(KalaBeanDataSource kalaBeanDataSource,CompositeDisposable compositeDisposable){
        this.kalaBeanDataSource = kalaBeanDataSource;
        this.compositeDisposable = compositeDisposable; 
= new ActivityKindList(); } public ActivityKindList getActivityKind(){
kalaBeanDataSource.getActivityKind().subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<ActivityKindList>() { @Override public void onSubscribe(Disposable d) { compositeDisposable.add(d); } @Override public void onSuccess(ActivityKindList activityKindList) {
activityKindListResult = activityKindList; } @Override public void onError(Throwable e) {
= e.toString(); } }); if(message == null && activityKindListResult.getItems().size() > 0){ return activityKindListResult; }else{ return null; } }


1 Reply
Commander Lvl 2
Message 2 of 2

Re: How can I make connection between retrofit and RxJava in different classes?

You'll need to show us exactly where you get the error, ideally with the closest entries in the stack trace.

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!