HashMap cannot be cast to messagestatus

I am getting a Fatal error that says:
Fatal Exception: main:
Java.lang.ClassCastException:java.util.HashMap cannot be cast to com.backendless.services.messaging.messageStatus atom…firebeaseplugin.firebase.backendless.BBackendlessHandler$2.handleResponse (BBackendlessHandler.java123) – code of this file is below
public class BBackendlessHandler implements BPushHandler, BUploadHandler {
private static final String TAG = BBackendlessHandler.class.getSimpleName();
private static final boolean DEBUG = Debug.BBackendlessPushHandler;
private boolean isSubscribed;
private Context context;
public void setContext(Context ctx) {
context = ctx;
}
public void initWithAppKey(String appKey, String secretKey, String versionKey)
{
Backendless.initApp(context, appKey, secretKey, versionKey);
}
@Override
public boolean subscribeToPushChannel(final String channel) {
if (!BNetworkManager.sharedManager().getNetworkAdapter().backendlessEnabled())
return false;
try {
Backendless.Messaging.registerDevice(context.getString(R.string.google_project_number), channel, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void response) {
if(DEBUG) Timber.v("Device has been subscribed to channel " + channel);
}
@Override
public void handleFault(BackendlessFault fault) {
if(DEBUG) Timber.v("Device subscription failed. " + fault.getMessage());
}
});
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public boolean unsubscribeToPushChannel(String channel) {
if (!BNetworkManager.sharedManager().getNetworkAdapter().backendlessEnabled())
return false;
// TODO: unsubscribe from push channel backendless
// http://support.backendless.com/t/push-notification-unregister-from-a-specific-channel
DeviceRegistration devReg = null;
try {
devReg = Backendless.Messaging.getDeviceRegistration();
} catch (Exception e) {
e.printStackTrace();
}
if(devReg != null) {
Backendless.Messaging.unregisterDevice();
}
return true;
}
@Override
public void pushToChannels(Collection<String> channels, JSONObject data) {
// Configure the header
PublishOptions publishOptions = new PublishOptions();
try {
publishOptions.putHeader(“android-ticker-text”, data.getString(BDefines.Keys.CONTENT));
publishOptions.putHeader(“android-content-title”, "Message from " + data.getString(BDefines.Keys.MESSAGE_SENDER_NAME));
publishOptions.putHeader(“android-content-text”, data.getString(BDefines.Keys.MESSAGE_PAYLOAD));
publishOptions.setPublisherId(data.getString(BDefines.Keys.MESSAGE_SENDER_ENTITY_ID));
} catch (JSONException e) {
e.printStackTrace();
}
// Only push to android devices
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushPolicy(PushPolicyEnum.ONLY);
deliveryOptions.setPushBroadcast(PushBroadcastMask.ALL);
// Publish a push notification to each channel
for(final String channel : channels) {
try {
data.put(BDefines.Keys.Channel, channel);
} catch (JSONException e) {
e.printStackTrace();
}
Backendless.Messaging.publish(channel, data.toString(), publishOptions, deliveryOptions, new AsyncCallback<MessageStatus>() {
@Override
public void handleResponse(MessageStatus response) {
if (DEBUG) Timber.v("Message published to channel: " + channel);
}
@Override
public void handleFault(BackendlessFault fault) {
if (DEBUG) Timber.v("Publish failed, " + fault.getMessage());
}
});
}
}
@Override
public Promise uploadFile(byte[] data, String name, String mimeType) {
return null;
}
}

Bel,

that’s a LOT of code to review… could you perhaps narrow it down to a specific block of code where the error occurs?

Also, make sure you are using the right version of the SDK: 3.x.x of the library will work with the 3.x backend, while 4.0.0-betaX will work with the 4.0 backend.

Regards,
Mark

yup for sure sorry about that:
the error message is reflected BELOW:

FATAL EXCEPTION: main
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.backendless.services.messaging.MessageStatus at com.plus.androidchatsdk.firebaseplugin.firebase.backendless.BBackendlessHandler$2.handleResponse(BBackendlessHandler.java:122)

& WHEN CLICKING ON BBackendlesshandler.java code relfected is the following(shortened :slight_smile: ):

Backendless.Messaging.publish(channel, data.toString(), publishOptions, deliveryOptions, new AsyncCallback&lt;MessageStatus&gt;() {
@Override
public void handleResponse(MessageStatus response) {
if (DEBUG) Timber.v("Message published to channel: " + channel);
}
@Override
public void handleFault(BackendlessFault fault) {
if (DEBUG) Timber.v("Publish failed, " + fault.getMessage());
}
});

As to the back endless version i am using the 3.0.0 and using it with the 3.0.25 one, so i don’t think that’s the issue

Hey Mark I have added the info below;.(I have actually added the information as comment)
Also, just FYI using Backendless and firebase together

Hi Bel,

I put together a simple project which contains the same publish call as you posted. It does work for me (will be happy to share if you’d like). I suspect the problem might be related to different class loaders, where the MessageStatus class is loaded by a different class loader than the one which loaded the activity class. Is it possible?

Regards,
Mark

Hi Mark,

Yes can you please share. Also will check looks like the class loader is not different going to test again and try and see if that’s the case and will update you soon; i am a beginner programer so please be patient with me.

Hi Bel,

No problem, you can download it from here:

Make sure to put your app id and secret key into the code - you will see where they should go in the main activity class.

Cheers,
Mark

I was able to run thanks for sending. When setup push message and send from backendless, it doesn’t push message to emulator i run it on, even though it says message scheduled on back endless side.
Good thing :slight_smile: though, when trying the code that gave error initially it seems like it is working no crash.
However, one question i have is when pushing from the device to the emulator unless running in the background it doesn’t push message to emulator. Is it expected not to get the push on emulator or is the API of emulator expected to be certain level to get the push when from back endless?
Thanks in advance

If the cast problem is resolved, we should close this topic and then you can submit another one for the push notification delivery issue.

Regards,
Mark

Hey Mark, actually i run into the initial crash again; hashmap cannot be cast to message status not sure if it’s the class loader; i can share the codes. Could it be something else other than that?

What has changed in the code since you got the project I shared with you?

Hey Mark, can’t seem to find the different loader; anyway was able to go around it by using the working backendless version i got, thanks. You can close the question