gpt4 book ai didi

java - 如何将自定义对象保存到 Parse 云 Android

转载 作者:行者123 更新时间:2023-11-30 02:20:57 25 4
gpt4 key购买 nike

现在我正在尝试将自定义对象保存到解析云中。我正在关注这个:

https://parse.com/docs/android_guide#objects

http://blog.parse.com/2013/05/30/parse-on-android-just-got-classier/

不幸的是,我得到了这个错误:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spicycurryman.hitup/com.spicycurryman.hitup.MainActivity}: java.lang.IllegalArgumentException: invalid type for value: class com.spicycurryman.hitup.model.HitupEvent



Caused by: java.lang.IllegalArgumentException: invalid type for value: class com.spicycurryman.hitup.model.HitupEvent
at com.parse.ParseObject.put(ParseObject.java:2746)
at com.spicycurryman.hitup.MainActivity.addEvent(MainActivity.java:257)
at com.spicycurryman.hitup.MainActivity.onCreate(MainActivity.java:84)

我猜这是由我创建的自定义对象类引起的:

package com.spicycurryman.hitup.model;

/**
* Created by Spicycurryman on 12/31/14.
*/

import java.util.ArrayList;

public class HitupEvent {
private String title, thumbnailUrl;
private int year;
private double rating;
private ArrayList<String> genre;

public HitupEvent() {
}

public HitupEvent(String name, String thumbnailUrl, int year, double rating,
ArrayList<String> genre) {
this.title = name;
this.thumbnailUrl = thumbnailUrl;
this.year = year;
this.rating = rating;
this.genre = genre;
}

public String getTitle() {
return title;
}

public void setTitle(String name) {
this.title = name;
}

public String getThumbnailUrl() {
return thumbnailUrl;
}

public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public double getRating() {
return rating;
}

public void setRating(double rating) {
this.rating = rating;
}

public ArrayList<String> getGenre() {
return genre;
}

public void setGenre(ArrayList<String> genre) {
this.genre = genre;
}

}

我像这样存储自定​​义对象:

   HitupEvent hitupEvent = new HitupEvent();




hitupEvent.setTitle("Rohit "+ "wants to "+WhatEvent_String_main+ " at "+ WhereEvent_String_main +" on "+ WhenEventDate_String_main +" ,"+ WhenEventTime_String_main );





hitupEvent.setThumbnailUrl(roro_photo);

hitupEvent.setGenre(singleAddress);


hitupEventList.add(hitupEvent);

adapter.notifyDataSetChanged();


ParseObject event = new ParseObject("event");
event.put("newHitupEvent", hitupEvent);


event.saveInBackground();
event.pinInBackground();

存储自定义对象的正确方法是什么?

最佳答案

如果你想以这种方式使用它,你应该使 HitUpEvent 成为 ParseObject 的子类,

您可以查看 Parse 文档:https://parse.com/docs/android_guide#subclasses了解更多相关信息。

子类化 ParseObject

To create a ParseObject subclass:

Declare a subclass which extends ParseObject. Add a @ParseClassName annotation. Its value should be the string you would pass into the ParseObject constructor, and makes all future class name references unnecessary.

确保您的子类具有公共(public)默认值(即零参数) 构造函数。您不得修改此中的任何 ParseObject 字段 构造函数。

在调用 Parse.initialize() 之前,在您的应用程序构造函数中调用 ParseObject.registerSubclass(YourClass.class)。

另一种选择是使用通用的 ParseObject 并执行如下操作:

event.put("genre", "hip-hop");
event.put("title", "tigga");

关于java - 如何将自定义对象保存到 Parse 云 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28555945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com