Exception due to wrong casting for certain device/OS ver


I publish a message using the following

Backendless.Messaging.publish( channelName, json.toString(), publishOptions,
        new AsyncCallback<MessageStatus>(){

            public void handleResponse(MessageStatus response) {


            public void handleFault(BackendlessFault fault) {


On my samsung s7 device with Android Ver 7, eveything works.

But on the Samsung S4 with Android ver 5.1, I get the followign exception

java.lang.ClassCastException: java.util.HashMap cannot be cast to com.backendless.messaging.MessageStatus
                                                                                 at com.xxx.fragments.ChatFragment$5.handleResponse(ChatFragment.java:239)
                                                                                 at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)

Which points to line 5 in the code above.

Can you assist? Thanks


I worked on the same problem just the other day and was not able to reproduce it. Here’s the project I created which uses this very API:

Could you try running on the device where you get a problem and see if also causes an error?


Hi Mark,

Running the project your sent me does not produce the crash. I tried it 3 times.
I also noticed that you are using backendless 3 with this. I tried to modify it to ver 4 and still I couldn’t reproduce it. I also tried to do it like my code but couldnt reproduce it.
Could it be related to user sending a message “while already” logged in?Anything I can do to help?


I do not think it is related to a logged in user. Here’s what you could do to help: try creating a similar smaller project which demonstrates the problem and share it with us. We’ll be happy to look into it. We need to have something which demonstrates the problem and unfortunately could not reproduce it.



I have been trying to create a mini sample but it is not producing it (spent few hours trying to mimic it). However I put a break point in my actual project and here is a screenshot of the returned object contents. Does this help at all?


It seems that the deserialization does not happen for some reason. Do you see any additional logs in LogCat, maybe some warnings?

Please try to specify the exact latest version, which is 4.0.0-beta4.


Yes I have the following

compile ‘com.backendless:backendless:4.0.0-beta4’

No I don’t see any thing out of the norms. Right now I go around this crash but not having the returned object cast to MessageStatus. I wish I can reproduce it in a mini project

What other dependencies do you have in the project?

Here is my dependeny list

dependencies {
compile fileTree(include: [’*.jar’], dir: ‘libs’)
androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2’, {
exclude group: ‘com.android.support’, module: ‘support-annotations’
compile ‘com.android.support:appcompat-v7:25.3.1’
compile ‘com.android.support:design:25.3.1’
compile ‘com.android.support.constraint:constraint-layout:1.0.2’
compile ‘com.github.shree-vastava:ValidUtil:v1.0’
compile ‘com.android.support:support-v4:25.3.1’
compile ‘com.backendless:backendless:4.0.0-beta4’
compile ‘com.squareup.picasso:picasso:2.5.2’
compile ‘com.google.android.gms:play-services-location:10.2.6’
compile ‘com.google.android.gms:play-services-maps:10.2.6’
compile ‘com.google.android.gms:play-services-identity:10.2.6’
compile ‘com.google.android.gms:play-services-gcm:10.2.6’
compile ‘com.google.android.gms:play-services-places:10.2.6’
compile ‘com.google.android.gms:play-services-ads:10.2.6’
compile ‘com.google.android.gms:play-services-base:10.2.6’
compile ‘de.hdodenhof:circleimageview:2.1.0’
compile ‘com.github.nicolasjafelle:paginglistview:1.2’
testCompile ‘junit:junit:4.12’
compile project(path: ‘:libs:chatmessageview’)

Also I notice when I ran the project you provided, it didn’t produce the error. Even if I used my API credential and used it in fragment, I couldnt reproduce it.
But when I replace the fragment I have in my actual project with the “small version of the new project” and integrated it, it produces the error. It leads me to think that it could be either something got setup on the server OR the sequence of events producing it.
The sequence of events are:
1- It checks if the user is logged in and if it does then it proceed, otherwise it logs him automatically. It registers the device for notifications. Then it proceed to send the message to another user by publishing to his channel. This is where the error happens.

Please note that this is a work for client of mine who signed up with your server ( after my recommendation and after I played with it for a bit). So if you need project info (his account) then please email me. I just dont want you to look at my “account” as it won’t have the related data

Why would you include the ‘libs’ folder into dependencies? What jars do you have there?

What do you mean by a small version of a new project? Maybe you could send us a minimal version of your code which would reproduce the problem? It would really help a lot.

Because in order to modify a gradle dependency (source files), you can’t just do compile. You need to download the library and add it as a library. I have one library which is a View/UI for chat

likee I said, I have been trying to do that but been unsucccessfull. By “small version of new project”, I mean the project that Mark sent. I tried replace the the file in “my project” with the file that mark sent me and that produced it. But it was the whole project not partial.

I understand that you cant fix it if you cant produce it but I cant produce it with small project. I will keep trying. For now, my work around is to not “down cast it”

I suspect the root cause of the problem is the heap space allocated to the app. I have seen reports of a similar problem and in many cases, those apps had a large number of dependencies. What I suspect is happening is some classes which use static values are being unloaded and thus loose the assigned values. This is what would be causing the mentioned ClassCastException. This also explains why the same code works in a simple project and exactly the same code fails inside of a larger app.

I’d be curious if adding

android:largeHeap =“true”

to the “application” element in the manifest file would make any difference. Could you try adding it and let us know the result?