We get an IncompatibleClassChangeError on a Samsung device when a user updates an application from the Play Store. Please check below log.
java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedName.value at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659) at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641) at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170) at java.lang.reflect.Field.getAnnotation(Field.java:242) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:71) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:67) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83) at com.google.gson.Gson.getAdapter(Gson.java:359) at com.google.gson.Gson.fromJson(Gson.java:809) at com.google.gson.Gson.fromJson(Gson.java:775) at com.google.gson.Gson.fromJson(Gson.java:724) at com.google.gson.Gson.fromJson(Gson.java:696) at com.cubii.utils.SessionManager.getUserID(SessionManager.java:70) at com.cubii.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:188) at com.cubii.BluetoothLeService.access$400(BluetoothLeService.java:47) at com.cubii.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:139) at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:443) at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)`enter code here` at android.os.Binder.execTransact(Binder.java:446)
And the code is as follows:
public int getUserID(){ try { String json = preferences.getString("User", ""); LoginResponse loginResponse = new Gson().fromJson(json, LoginResponse.class);//getting error from this line Integer id = 0; if (loginResponse != null) { if (loginResponse.getId() != null) { id = loginResponse.getId(); } else { id = loginResponse.getUserId(); } } return (id == null) ? 0 : id; }catch (Exception e){ Logger.dump(e); } return 0; }
LoginResponse is my POJO class.
preferences.getString("User", "")
will return a JSON string, which is the server response.
android gson
Sanjay kakadiya
source share