0

I am getting strange issue with some of the Android Devices (ranging from Android OS 4 to 6) with the above error. I have made a class named Response observer, which further extends my Observer class. (Class attached):

public abstract class ResponseObserver<T extends ServerResponse> implements Observer<T> {
    private static final Handler HANDLER = new Handler();

    @Override
    public void onChanged(@Nullable final T response) {
        onResponse(response);
        if (Common.nonNull(response)) {
            if (isOk(response)) {
                if(HandlerResponseCode.STATUS_SUCCESS.equals(response.getStatus())) {
                    new Handler().post(new Runnable() {
                        @Override
                        public void run() {
                            onSuccess(response);
                        }
                    });

                } else {
                    if (Common.nonNull(response.getError()))
                        onFail(response);
                    else
                        onNonFailureResponse(response);
                }
            } else {
                onNotOk(response);
            }
        }else{
            onNullResponse(response);
        }

    }

    public void onNullResponse(T response) {

    }

    public void onNonFailureResponse(T response) {
        // empty on purpose
    }

    public void onNotOk(@Nullable T response) {
        // empty on purpose
    }

    /**
     * Called as soon as the response is received. Implementors are responsible for null checks.
     *
     * @param response response object or null
     */
    public void onResponse(@Nullable T response) {
        // empty on purpose
    }

    /**
     * By default always return true which indicates no extra checks are required.
     *
     * @param response response from server
     * @return always true
     */
    public boolean isOk(T response) {
        return true;
    }

    public abstract void onSuccess(@Nullable T response);

}

Logcat (Crash details)

Fatal Exception: java.lang.NoClassDefFoundError: com/zotopay/zoto/datamodels/ResponseObserver
       at com.zotopay.zoto.activityviews.SplashActivity.fetchSMSKeywords(SplashActivity.java:102)
       at com.zotopay.zoto.activityviews.SplashActivity.loadDashboard(SplashActivity.java:164)
       at com.zotopay.zoto.activityviews.SplashActivity.continueLaunch(SplashActivity.java:193)
       at com.zotopay.zoto.activityviews.SplashActivity.onCreate(SplashActivity.java:77)
       at android.app.Activity.performCreate(Activity.java:5442)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.access$800(ActivityThread.java:166)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5584)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)

And I am calling this observer like this:

smsLiveDataModel.fetchLiveDataFromService().observe(this, new ResponseObserver<SMSResponse>() {
                @Override
                public void onSuccess(@Nullable SMSResponse response) {

                }


            });

And it is crashing on line where I have made new ResponseObserver. Strange issue, I don't know why the hell is crashing.

Please help

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • [Check out this answer](https://stackoverflow.com/questions/8678630/noclassdeffounderror-for-code-in-an-java-library-on-android) – Mohammed Farhan Nov 23 '17 at 07:14
  • @MohammedFarhan Old school. this is a runtime crash on some devices. I am working on Android Studio not old eclipse – Gaurav Arora Nov 23 '17 at 07:25

0 Answers0