Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot cast object to hashmap

Tags:

java

hashmap

My code:

Object res =  stub.call(sessionId, "sale.list", "11111");
HashMap<String, String> map = (HashMap<String, String>) res;

Converting object into HashMap i got following exception,

Exception in thread "main" java.lang.ClassCastException: [Ljava.util.HashMap;   
cannot be cast to java.util.HashMap

Can anyone help me how to retrieve object data?

like image 947
user2698746 Avatar asked Feb 07 '26 04:02

user2698746


1 Answers

You can cast res to HashMap only if stub.call(sessionId, "sale.list", "11111") returns a HashMap object.

[Ljava.lang.HashMap; indicates that what you are getting is an array of hashMap and not a single HashMap.

like image 180
Juned Ahsan Avatar answered Feb 09 '26 16:02

Juned Ahsan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!