com.parse.ParseObject无法转换为

时间:2019-01-15 07:02:28

标签: java android parse-platform parse-server parse-sdk-android

我正在开发具有Parse Platform的应用程序。要获取数据,我正在调用ParseCloud.callFunctionInBackground函数。

我已经将解析及其子类注册到Application类中,如下所示:

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());
    }
}

我在下面的模型类中扩展了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);
    }

}

当我从片段中调用以下方法时:

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 {
                }
    }
});

但是我遇到了以下异常:

  

java.lang.ClassCastException:com.parse.ParseObject无法转换为   com.example.ParseMessage

我已经在Google和Stackoverflow上搜索了很多信息,但没有得到任何解决方案。任何人都可以帮我解决这个问题,因为我已经花了很多时间了。下面是我从Parse得到的响应:

Response from Parse

1 个答案:

答案 0 :(得分:0)

您提供的信息不是很具体,但是从调试器屏幕上看,您似乎正在尝试将ParsePhoto转换为ParseMessageParsePhotoParseObject的子类,我认为这是造成此问题的原因。