5

I am developing application which having Parse Platform. To fetch data I am calling ParseCloud.callFunctionInBackground function.

I have registered the Parse and its sub class into the Application class like below :

public class App extends Application {
    @Override
    public void onCreate(){
        super.onCreate();
        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);    
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.networkInterceptors().add(httpLoggingInterceptor);    
        ParseObject.registerSubclass(ParseMessage.class);
        Parse.initialize(new Parse.Configuration.Builder(this)
                        .applicationId("KEY")
                        .server("URL")
                        .build());
    }
}

I have below model class which extends ParseObject :

@ParseClassName("ParseMessage")
public class ParseMessage extends ParseObject {

    // Ensure that your subclass has a public default constructor
    public ParseMessage() {
        super();
    }

    public ParsePhoto getPhotos() {
        return (ParsePhoto) getParseObject("photos");
    }

    public void setPhotos(ParsePhoto value) {
        put("photos", value);
    }

    public String getCaption() {
        return getString("caption");
    }

    public void setCaption(String value) {
        put("caption", value);
    }

}

When I calling this below method from my Fragment :

HashMap<String, Object> params = new HashMap<String, Object>();
ParseCloud.callFunctionInBackground("MY_METHOD", params, new FunctionCallback<ArrayList<ParseMessage>>() {
            public void done(ArrayList<ParseMessage> mapObject, ParseException e) {
                if (e == null) {
                    ParseMessage object = mapObject.get(i);
                    }
                } else {
                }
    }
});

But I am getting below exception :

java.lang.ClassCastException: com.parse.ParseObject cannot be cast to com.example.ParseMessage

I already searched lots of thins from Google and Stackoverflow, but I did not get any solutions of it. Can anyone help me into this as I already spend a lot of time on this. Below response which I am getting from Parse :

Response from Parse

Manuel
  • 14,274
  • 6
  • 57
  • 130
Ronak Joshi
  • 1,553
  • 2
  • 20
  • 43

1 Answers1

0

The info you have provided is not very concrete, but from the debugger screen, it looks like you are trying to convert ParsePhoto into ParseMessage. ParsePhoto is subclass of ParseObject, and I believe this is causing the issue.

Andy Sug
  • 234
  • 2
  • 7
  • I am not sure which additional information is remain in my discretion, but as per your comment let me give quick review, ParseMessage is the parent class which having ParsePhoto, Caption and other parameters. So, here ParsePhoto is a child class. – Ronak Joshi Jan 22 '19 at 07:16
  • From the sreenshot you have provided ,it looks like you are getting objects of type ParseObject but you are trying to store in a reference of type ParseMessage which is subclass of ParseObject. – Ripudaman Singh Jan 22 '19 at 13:28
  • Yes @RipudamanSingh, but is this possible that I can get ParseMessage based response directly from parse platform? – Ronak Joshi Jan 25 '19 at 10:17
  • @RonakJoshi, I'm a bit confused with your wording "ParseMessage is the parent class which having ParsePhoto, ..., So, here ParsePhoto is a child class". If `ParsePhoto` is an instance field of `ParseMessage`, then it won't become a _child_ of `ParseMessage`. Can you post the complete definition of both `ParsePhoto` and `ParseMessage`? – Andy Sug Jan 25 '19 at 11:10