我正在开发具有Parse Platform的应用程序。要获取数据,我正在调用ParseCloud.callFunctionInBackground
函数。
我已将 Parse 及其子类注册到 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);
}
}
当我从我的 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 {
}
}
});
但我得到以下异常:
java.lang.ClassCastException:com.parse.ParseObject 无法转换为 com.example.ParseMessage
我已经从 Google 和 Stackoverflow 搜索了很多东西,但我没有得到任何解决方案。任何人都可以帮助我解决这个问题,因为我已经花了很多时间在这上面。下面是我从 Parse 得到的回复: