java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap

I have a problem with saving my data to the database of backendless.I have a class named Item with several attributes and a list of Tag.which tag is also a custom class with only a tagtext string attribute.I have created the schema in the Data and when I want to save the data I get this error:

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap

Hi, Saeed.
Please, provide appId of your application or describe data scheme more detailed. Because i have tried according to your description and for me all works.

This is my appid : BC9120DC-3E6F-DE66-FF91-199819BBAD00
This is my Item class :

public class Item { 
 private String name,description,picPath,reward, lostDate,objectId,contact; 
 private GeoPoint location; 
 private boolean lost; 
 private List<Tag> tags; 
 
 public Item() { 
 } 
 
 public Item(String date, String description, GeoPoint location, boolean lost, String name, String picPath, String reward,String contact) { 
 this.lostDate = date; 
 this.description = description; 
 this.location = location; 
 this.lost = lost; 
 this.name = name; 
 this.picPath = picPath; 
 this.reward = reward; 
 this.contact = contact; 
 } 
 
 public String getContact() { 
 return contact; 
 } 
 
 public void setContact(String contact) { 
 this.contact = contact; 
 } 
 
 public String getLostDate() { 
 return lostDate; 
 } 
 
 public void setLostDate(String lostDate) { 
 this.lostDate = lostDate; 
 } 
 
 public String getDescription() { 
 return description; 
 } 
 
 public void setDescription(String description) { 
 this.description = description; 
 } 
 
 public GeoPoint getLocation() { 
 return location; 
 } 
 
 public void setLocation(GeoPoint location) { 
 this.location = location; 
 } 
 
 public boolean isLost() { 
 return lost; 
 } 
 
 public void setLost(boolean lost) { 
 this.lost = lost; 
 } 
 
 public String getName() { 
 return name; 
 } 
 
 public void setName(String name) { 
 this.name = name; 
 } 
 
 public String getPicPath() { 
 return picPath; 
 } 
 
 public void setPicPath(String picPath) { 
 this.picPath = picPath; 
 } 
 
 public String getReward() { 
 return reward; 
 } 
 
 public void setReward(String reward) { 
 this.reward = reward; 
 } 
 
 public String getObjectId() { 
 return objectId; 
 } 
 
 public void setObjectId(String objectId) { 
 this.objectId = objectId; 
 } 
 
 public List<Tag> getTags() { 
 return tags; 
 } 
 
 public void setTags(List<Tag> tags) { 
 this.tags = tags; 
 } 
 
 public void addTag( Tag tag ) 
 { 
 if( tags == null ) 
 tags = new ArrayList<Tag>(); 
 tags.add( tag ); 
 } 
}


and this is my Tag class :

public class Tag { 
 private String tagText,objectId; 
 
 public Tag() { 
 } 
 
 public Tag(String tagText){ 
 this.tagText = tagText; 
 } 
 
 public String getTagText() { 
 return tagText; 
 } 
 
 public void setTagText(String tagText) { 
 this.tagText = tagText; 
 } 
 
 public String getObjectId() { 
 return objectId; 
 } 
 
 public void setObjectId(String objectId) { 
 this.objectId = objectId; 
 } 
}


and here is my schema build in the backendless :
http://support.backendless.com/public/attachments/64320919cc463a47917271fcbcd3b1cd.png</img>

and here is how I am saving :

HashMap item2send = new HashMap(); 
item2send.put( "___class", "Item" ); 
item2send.put( "name", item.getName() ); 
item2send.put( "description", item.getDescription() ); 
item2send.put( "reward", item.getReward() ); 
item2send.put( "contact", item.getContact() ); 
item2send.put( "picPatch", f.getFileURL() ); 
item2send.put( "lostDate", item.getLostDate() ); 
item2send.put( "lost", true ); 
item2send.put( "location", item.getLocation() ); 
item2send.put( "tags",listtags ); 
 

Object b=Backendless.Persistence.of(Item.class).save(item2send);


http://support.backendless.com/public/attachments/fa609c4dd44f0a430010a373a6fb6140.png</img>

Hi Saeed,

When you use hashmaps for data objects, you should use the following API to save them:

Backendless.Persistence.of("Item").save(item2send);

Notice the argument for the “of” method is a String.

Cheers,
Mark