简体   繁体   中英

You must register this ParseObject subclass before instantiating it

I am getting the following error in my Android application using Parse :

You must register this ParseObject subclass before instantiating it.

In my Application object, I am doing the following inside 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:

 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); before calling 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 .


Reference: Subclassing Parse Object

You also have to put it in your Manifest like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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