ClassCastException: class can not be case to itself on android using dagger - java

Recently I started to observe a lot of exceptions of this kind.
The classes that can not be casted to itself are injected by dagger.
By the way, I'm using multidex build in gradle.
Log look like the following:
FATAL EXCEPTION: main
Process: com.ui.client.debug, PID: 22087
java.lang.ClassCastException: com.logic.feed.FeedManager cannot be cast
to com.logic.feed.FeedManager
at com.logic.topic.TopicHandler$$InjectAdapter.get(TopicHandler$$InjectAdapter.java:73)
at com.logic.topic.TopicHandler$$InjectAdapter.get(TopicHandler$$InjectAdapter.java:19)
at com.ui.client.module.MainActivityModule$$ModuleAdapter$ProvideTopicHandlerProvidesAdapter.get(MainActivityModule$$ModuleAdapter.java:1244)
at com.ui.client.module.MainActivityModule$$ModuleAdapter$ProvideTopicHandlerProvidesAdapter.get(MainActivityModule$$ModuleAdapter.java:1208)
at com.ui.topic.TopicScene$$InjectAdapter.injectMembers(TopicScene$$InjectAdapter.java:73)
at com.ui.topic.TopicScene$$InjectAdapter.injectMembers(TopicScene$$InjectAdapter.java:23)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:281)
at com.ui.core.base.BaseActivity.inject(BaseActivity.java:35)
at com.ui.core.base.BaseFragment.onActivityCreated(BaseFragment.java:54)
at android.app.Fragment.performActivityCreated(Fragment.java:2122)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.BackStackRecord.run(BackStackRecord.java:833)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

If you still haven't figured a solution, it might be Samsung's faulty implementation of MultiDex on theEuropean variant of the Galaxy S5 on 5.0:
https://stackoverflow.com/a/29008480/477243
I've had plenty of similar crashes reported (ClassCastException on casting a class to itself).
Upon reading the linked answer I've checked the devices which were generating the crash, all of them were SM G900F on Android 5.0, which is a shame since my App is available only on UK and Netherlands and the GS5 is one of our top devices (11.5% of the users).

Related

Android version compatibility for Math.toIntExact Utility method

The Math.toIntExact method is throwing an exception on my Android 6.0 emulator. (More recent emulator versions are ok)
This Microsoft doc is the only doc I found about it. Am I correct in thinking that Math.toIntExact is not compatible before Android 9.0 ?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dmurphy.remotescrumpoker, PID: 9527
java.lang.NoSuchMethodError: No static method toIntExact(J)I in class Ljava/lang/Math; or its super classes (declaration of 'java.lang.Math' appears in /system/framework/core-libart.jar)
at com.dmurphy.remotescrumpoker.Activity_TeamDetails$6.onComplete(Activity_TeamDetails.java:268)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
D/FA: Event not sent since app measurement is disabled
Math::toIntExact, as per the documentation, has been introduced with API level 24, that is Android 7.0. So yeah, it's not available on Android 6.
The good news is that you can easily implement it yourself by extracting it from the java.lang.Math source code.
public static int toIntExact(long value) {
if ((int)value != value) {
throw new ArithmeticException("integer overflow");
}
return (int)value;
}

Android app crashes when minifyEnabled is true

I am using a multi-module app and the app crashes when minifyEnabled true in the installed module's build.gradle.
Following is the deobfuscated stacktrace I retrieved from play console.
FATAL EXCEPTION: ControllerMessenger
Process: com.packagename, PID: 16978
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
at com.packagename.login.Utils.AuthenticationActions.saveCredentials(AuthenticationActions.java)
at com.packagename.login.LoginActivity$1$1.onCompleted(LoginActivity.java)
at com.packagename.login.LoginActivity$1$1.onCompleted(LoginActivity.java)
at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
at com.koushikdutta.ion.IonRequestBuilder$EmitterTransform$1.onCompleted(IonRequestBuilder.java)
at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
at com.koushikdutta.ion.IonRequestBuilder$1.run(IonRequestBuilder.java)
at com.koushikdutta.async.AsyncServer$RunnableWrapper.run(AsyncServer.java)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at androidx.test.espresso.base.Interrogator.a(Interrogator.java:19)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:166)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:158)
at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:34)
at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:77)
at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:52)
at androidx.test.espresso.action.Tap.c(Tap.java:8)
at androidx.test.espresso.action.Tap.b(Tap.java:18)
at androidx.test.espresso.action.Tap$1.a(Tap.java:3)
at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:22)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:9)
at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:79)
at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:96)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I am unable to understand what does this code correspond to 'java.lang.Object java.util.List.get(int)'
I am using multiple external libraries, one of which is ion koush.
I have tried adding this to ever proguard-rules.pro file in my project
-keep class com.koushikdutta.** { *;}. But this didn't yield any success.
This happens when your app transform json to POJOs and you have minify enable. Minify change those POJOs making the transformation impossible (it will compile, but all your POJOs propierties will be null).
Keep those POJOs adding -keep class com.packagename.<path to pojos> {*; } to your proguard-rules file.
Also add "#Keep" above class name to all Pojo files.

Java android event bus open camera

On android 7.0 when I want to open a camera in logs I see this :
EventBus: Could not dispatch event: class pl.eltegps.smokkomunikator.event.PhotoRequestedEvent to subscribing class class pl.eltegps.smokkomunikator.ui.activity.MainActivity
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/pl.eltegps.smokkomunikator/images/gps_TEMP.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9483)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9468)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.Activity.startActivityForResult(Activity.java:4399)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:4358)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
at pl.eltegps.smokkomunikator.ui.activity.MainActivity.onPhotoRequestedEvent(MainActivity.java:399)
at java.lang.reflect.Method.invoke(Native Method)
at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:416)
at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:397)
at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:370)
at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
at pl.eltegps.smokkomunikator.ui.fragment.NewMessageFragment.photo(NewMessageFragment.java:259)
at pl.eltegps.smokkomunikator.ui.fragment.NewMessageFragment$$ViewBinder$1.doClick(NewMessageFragment$$ViewBinder.java:28)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:6199)
at android.view.View$PerformClick.run(View.java:23647)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
On android 4.4.2 I check and it works corretly, but on new android it doesn't works corretly and I don't know why ...
This is a problem I faced also faced while testing on 7.0 . Seems like you can not use getUri() Directly on 7.0 without the use of content provider.
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".provider", f));
You will have to use this and add a provider.xml in xml directory of your project.
this link has detailed explaination about it.

Quickblox: Android Video Calling Shows java.lang.NoSuchMethodError: No static method registerComplexPropertyParser

Used native-libs.jar. Following the same method as given in the sample. Currently using quickblox-android-sdk-videochat-webrtc-2.4. Trying using the sample code QBRTCClient shows the below error message:
java.lang.NoSuchMethodError: No static method registerComplexPropertyParser(Ljava/lang/String;Lcom/quickblox/chat/propertyparsers/MessagePropertyParser;)V in class Lcom/quickblox/chat/model/QBChatMessageExtension; or its super classes (declaration of 'com.quickblox.chat.model.QBChatMessageExtension' appears in /data/app/xxx.xxx.xxx/base.apk)
at com.quickblox.videochat.webrtc.RTCSignallingMessageProcessor.<clinit>(RTCSignallingMessageProcessor.java:38)
at com.quickblox.videochat.webrtc.QBRTCClient.<init>(QBRTCClient.java:93)
at com.quickblox.videochat.webrtc.QBRTCClient.getInstance(QBRTCClient.java:124)
at xxx.xxx.xxx.Activity.CallActivity.initQBRTCClient(CallActivity.java:125)
at xxx.xxx.xxx..Activity.CallActivity.onCreate(CallActivity.java:119)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2312)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2421)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5329)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
I was using multiple version of library for chat, video and core, so i contacted Quickblox and they told me to use the same version of library for all. Hope this helps.
Thank You

Google Maps API Android - NullPointerException - setBoundsInParent

In our Android mobile application (compatible with Android versions 4.0 and upper), we use Google Maps API V2.
We get some bug reports from users on some kinds of devices (Android versions 4.3, 4.4 and 5.0) with a NullPointerException in setBoundsInParent method of android.view.accessibility.AccessibilityNodeInfo class.
The application crashes when the user tries to move or to zoom on the map.
The problem only appears for some users - devices. Most of our customers do not have that problem.
The problem seems to come from the use of the setPadding method of Google Maps API to position the Google logo so that it is always clearly visible on the map :
#Override
protected void onCreate(Bundle savedInstanceState)
{
...
// Initialize map
...
// Sets the padding for the map
if(mMap!=null)
{
mMap.setPadding(0, DPI.toPixels(100), 0, DPI.toPixels(100));
}
...
}
Removing the call to the setPadding method seems to resolve the problem for affected users but it is not a valid solution for us because we need to position the Google logo with this method.
We cannot reproduce this problem on our development devices, so it's difficult for us to find the real origin of this problem.
You will find the full stacktraces of the bug below.
Does someone have an idea?
Thanks a lot in advance for your answer.
Best regards.
Stacktrace on Android 4.3 - 4.4
java.lang.NullPointerException
at android.view.accessibility.AccessibilityNodeInfo.setBoundsInParent(AccessibilityNodeInfo.java:1012)
at android.support.v4.view.a.k.c(SourceFile:819)
at android.support.v4.view.a.i.b(SourceFile:1850)
at com.google.maps.api.android.lib6.c.et.a(Unknown Source)
at android.support.v4.widget.ab.a(SourceFile:56)
at android.support.v4.widget.ac.a(SourceFile:717)
at android.support.v4.view.a.x.a(SourceFile:112)
at android.support.v4.view.a.ad.createAccessibilityNodeInfo(SourceFile:42)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:724)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147)
at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:971)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Stacktrace on Android 5.0
java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Rect.left' on a null object reference
at android.view.accessibility.AccessibilityNodeInfo.setBoundsInParent(AccessibilityNodeInfo.java:1316)
at android.support.v4.view.a.k.c(SourceFile:819)
at android.support.v4.view.a.i.b(SourceFile:1850)
at com.google.maps.api.android.lib6.c.et.a(Unknown Source)
at android.support.v4.widget.ab.a(SourceFile:56)
at android.support.v4.widget.ac.a(SourceFile:717)
at android.support.v4.view.a.x.a(SourceFile:112)
at android.support.v4.view.a.ad.createAccessibilityNodeInfo(SourceFile:42)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:894)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:155)
at android.view.AccessibilityInteractionController.access$400(AccessibilityInteractionController.java:53)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
The bug has been confirmed by Google : http://code.google.com/p/gmaps-api-issues/issues/detail?id=7619
Best regards.

Categories