com.parse.ParseObject cannot be cast to

允我心安 提交于 2019-12-07 07:58:59

问题


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 :


回答1:


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.



来源:https://stackoverflow.com/questions/54194064/com-parse-parseobject-cannot-be-cast-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!