Search code examples
javaandroidkotlinsignalrbroadcastreceiver

Boolean::class.java can not cast to boolean (java) when receive data from Signal R and pass to broadcast receiver


I'm Android Developer and I Used Signal R for communication with Server and get data when emitting from server:

hubConnection.on(
    Constants.SIGNALR_TARGET_RECEIVE_CALL_REQUEST,
    { receiveCallRequestDetails, isVideoEnable ->
        intent.putExtra(BROADCAST_SIGNAL_R_RECEIVE_CALL_REQUEST_DETAILS, receiveCallRequestDetails)
        intent.putExtra(BROADCAST_SIGNAL_R_RECEIVE_CALL_REQUEST_IS_VIDEO, isVideoEnable)
        LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(intent)
        // applicationContext.sendBroadcast(intent)
    },
    ReceiveCallRequest::class.java,
    Boolean::class.java
)

when I get Boolean from the server(isVideoEnable is Boolean) and pass it to BroadcastReceiver I got RunTimeError with this description:

HubConnection disconnected with WebSocket connection stopping with code null and reason 'Cannot cast java.lang.Boolean to boolean'.


Solution

  • It normally should be able to but you could change it from Boolean (object type) to boolean (primitive type).