Right now I am trying to save a custom made object to the parse cloud. I am following this:
https://parse.com/docs/android_guide#objects
http://blog.parse.com/2013/05/30/parse-on-android-just-got-classier/
Unfortunately, I get this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spicycurryman.hitup/com.spicycurryman.hitup.MainActivity}: java.lang.IllegalArgumentException: invalid type for value: class com.spicycurryman.hitup.model.HitupEvent
Caused by: java.lang.IllegalArgumentException: invalid type for value: class com.spicycurryman.hitup.model.HitupEvent
at com.parse.ParseObject.put(ParseObject.java:2746)
at com.spicycurryman.hitup.MainActivity.addEvent(MainActivity.java:257)
at com.spicycurryman.hitup.MainActivity.onCreate(MainActivity.java:84)
I guess it was caused by the custom object class I created:
package com.spicycurryman.hitup.model;
/**
* Created by Spicycurryman on 12/31/14.
*/
import java.util.ArrayList;
public class HitupEvent {
private String title, thumbnailUrl;
private int year;
private double rating;
private ArrayList<String> genre;
public HitupEvent() {
}
public HitupEvent(String name, String thumbnailUrl, int year, double rating,
ArrayList<String> genre) {
this.title = name;
this.thumbnailUrl = thumbnailUrl;
this.year = year;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String name) {
this.title = name;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
public ArrayList<String> getGenre() {
return genre;
}
public void setGenre(ArrayList<String> genre) {
this.genre = genre;
}
}
and I am storing the custom object like this:
HitupEvent hitupEvent = new HitupEvent();
hitupEvent.setTitle("Rohit "+ "wants to "+WhatEvent_String_main+ " at "+ WhereEvent_String_main +" on "+ WhenEventDate_String_main +" ,"+ WhenEventTime_String_main );
hitupEvent.setThumbnailUrl(roro_photo);
hitupEvent.setGenre(singleAddress);
hitupEventList.add(hitupEvent);
adapter.notifyDataSetChanged();
ParseObject event = new ParseObject("event");
event.put("newHitupEvent", hitupEvent);
event.saveInBackground();
event.pinInBackground();
What would be the proper way to store custom objects?
If you wish to use it this way you should make HitUpEvent subclass ParseObject ,
You can check out Parse documentation : https://parse.com/docs/android_guide#subclasses to learn more about this.
Subclassing ParseObject
To create a ParseObject subclass:
Declare a subclass which extends ParseObject. Add a @ParseClassName annotation. Its value should be the string you would pass into the ParseObject constructor, and makes all future class name references unnecessary.
Ensure that your subclass has a public default (ie zero-argument) constructor. You must not modify any ParseObject fields in this constructor.
CallParseObject.registerSubclass(YourClass.class) in your Application constructor before calling Parse.initialize().
Another option is to use a generic ParseObject and do something like this:
event.put("genre", "hip-hop");
event.put("title", "tigga");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.