Reputation: 38
I am trying to SubClass a ParseObject, which seems to work ok except the method can't be resolved. Android Studio seems to be able to find the class - at least the IDE links back to the original class PhotoSession, it just can't find the method and I get a cannot resolve method error.
import com.parse.ParseClassName;
import com.parse.ParseObject;
@ParseClassName("PhotoSession")
public class PhotoSession extends ParseObject {
public PhotoSession() {
}
public void setDisplayName(String value) {
put("displayName", value);
}
}
Creating a PhotoSession object from another class:
private void createNewSession() {
ParseUser user = ParseUser.getCurrentUser();
ParseObject photoSession = new PhotoSession();
photoSession.setDisplayName("test session");
}
I've registered the class in the Application class before Parse.initialize(...) like so:
ParseObject.registerSubclass(PhotoSession.class);
Upvotes: 0
Views: 658
Reputation: 3118
Look closely here:
private void createNewSession() {
ParseUser user = ParseUser.getCurrentUser();
ParseObject photoSession = new PhotoSession();
photoSession.setDisplayName("test session");
}
The problem is this line:
ParseObject photoSession = new PhotoSession();
You are creating a new PhotoSession object but with type ParseObject. Create it with type PhotoSession instead:
PhotoSession photoSession = new PhotoSession();
Since PhotoSession is a subclass of ParseObject, it is valid to declare a new PhotoSession as a type ParseObject. You don't want that though, because that is casting it to it's parent class, which removes any specific methods that exist in a PhotoSession object. This is called upcasting, and in this case you do not want to do that
Upvotes: 2