[英]You must register this ParseObject subclass before instantiating it
I am getting the following error in my Android
application using Parse
: 我在使用
Parse
Android
应用程序中收到以下错误:
You must register this ParseObject subclass before instantiating it.
In my Application
object, I am doing the following inside onCreate
: 在我的
Application
对象中,我在onCreate
执行以下操作:
Parse.enableLocalDatastore(this);
Parse.initialize(this, "code", "code");
So why am I still getting this error? 那么为什么我仍然会收到此错误? It was working fine yesterday but it's all of a sudden stopped working.
它昨天工作正常,但它突然停止工作。
This is my Manifest file: 这是我的清单文件:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
....
LogCat: logcat的:
java.lang.IllegalArgumentException: You must register this ParseObject subclass before instantiating it.
at com.parse.ParseObject.<init>(ParseObject.java:157)
at com.parse.ParseObject.<init>(ParseObject.java:119)
at usmaan.app.models.Game.<init>(Game.java:25)
at usmaan.app.models.Game.to(Game.java:86)
at usmaan.app.adapters.GamesAdapter.getView(GamesAdapter.java:47)
at android.widget.AbsListView.obtainView(AbsListView.java:2344)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
You must call ParseObject.registerSubclass(YourClassName.class);
您必须调用
ParseObject.registerSubclass(YourClassName.class);
before calling Parse.initialize()
. 在调用
Parse.initialize()
之前。
In addition, you need to annotate your custom class like this: 此外,您需要注释您的自定义类,如下所示:
@ParseClassName("YourClassName")
public class YourClassName extends ParseObject
{
}
Finally, your custom class needs a default no-args constructor in order to be registered by ParseObject
. 最后,您的自定义类需要一个默认的无参数构造函数才能由
ParseObject
注册。
Reference: Subclassing Parse Object 参考: 子类化解析对象
You also have to put it in your Manifest like this: 你还必须把它放在你的Manifest中:
<application
android:name="ParseApplication"
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
YOUR ACTIVITY 1
/>
<activity
YOUR ACTIVITY 2
/>
</application>
And then try swapping these following lines 然后尝试交换以下这些行
Parse.enableLocalDatastore(this);
Parse.initialize(this, "key", "key");
like this: 像这样:
Parse.initialize(this, "key", "key");
Parse.enableLocalDatastore(this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.