简体   繁体   English

无法保存扩展ParseObject的类

[英]Unable to save class that extends ParseObject

Im trying to save the ParseObject. 我试图保存ParseObject。 And while the class is being created on Parse, the values and required rows dont seem to be getting added. 当在Parse上创建类时,值和所需的行似乎没有被添加。

ParseDetailsItem ParseDetailsItem

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

private String fName;
private String lName;
private int age;

    public ParseDetailsItem(String fName,String lName,int age)
    {
        super();

        this.fName = fName;
        this.lName = lName;
        this.age   = age;
    }
}

save() 救()

    s_fName = et1.getText().toString();
    s_lName = et2.getText().toString();
    s_age   = Integer.parseInt(et3.getText().toString());

    ParseDetailsItem t = new ParseDetailsItem(s_fName,s_lName,s_age);

    t.setfName(s_fName);
    t.setlName(s_lName);
    t.setAge(s_age);

    t.saveInBackground();

Previously i'd been saving it like this and that seemed to work: 以前我一直在保存它,这似乎工作:

    pObject = new ParseObject("Details");
    pObject.put("fName",s_fName);
    pObject.put("lName",s_lName);
    pObject.put("Age",s_age);
    pObject.saveInBackground();

I guess im missing the put() method somewhere, but not sure where to call it? 我想我错过了某个地方的put()方法,但不知道在哪里调用它?

Edit This works, but is this the only way? 编辑这是有效的,但这是唯一的方法吗?

    t.put("fName", s_fName);
    t.put("lName", s_lName);
    t.put("Age", s_age);

Edit2 EDIT2

Is there a shorter way of doing it rather than calling put for each value? 是否有更短的方式来做,而不是为每个值调用put? Say if I pass the values to the constructor and call put() just for the ParseObject-Class. 假如我将值传递给构造函数并仅为ParseObject-Class调用put()。 Like this: 像这样:

ParseDetailsItem t = new ParseDetailsItem(s_fName,s_lName,s_age);
t.saveInBackground();

The subclasses of ParseObject should have only a zero-argument constructor. ParseObject的子类应该只有一个零参数构造函数。 From the documentation : 文档

Subclassing ParseObject 子类化ParseObject

To create a ParseObject subclass: 要创建ParseObject子类:

  1. Declare a subclass which extends ParseObject. 声明一个扩展ParseObject的子类。
  2. Add a @ParseClassName annotation. 添加@ParseClassName注释。 Its value should be the string you would pass into the ParseObject constructor, and makes all future class name references unnecessary. 它的值应该是您将传递给ParseObject构造函数的字符串,并且不需要所有将来的类名引用。
  3. Ensure that your subclass has a public default (ie zero-argument) constructor. 确保您的子类具有公共默认值(即零参数)构造函数。 You must not modify any ParseObject fields in this constructor. 您不得修改此构造函数中的任何ParseObject字段。
  4. Call ParseObject.registerSubclass(YourClass.class) in your Application constructor before calling Parse.initialize(). 在调用Parse.initialize()之前,在Application构造函数中调用ParseObject.registerSubclass(YourClass.class)。

Now what you should do is something like this: 现在你应该做的是这样的事情:

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

    private String fName;
    private String lName;
    private int age;

    public ParseDetailsItem()
    {
        super();
    }

    public void setDetail(String fName,String lName,int age)
    {
        this.fName = fName;
        this.lName = lName;
        this.age   = age;
    }
}

and then call it: 然后调用它:

ParseDetailsItem t = new ParseDetailsItem();
t.setDetail(s_fName,s_lName,s_age);
t.saveInBackground();

Let me know if you manage to get it working, in my code the above works just fine 让我知道如果你设法让它工作,在我的代码中,上面的工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM