Backendless.Messaging.publish( channelName, json.toString(), publishOptions,
new AsyncCallback<MessageStatus>(){
@Override
public void handleResponse(MessageStatus response) {
}
@Override
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)
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.
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
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
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?