簡體   English   中英

您必須在實例化之前注冊此ParseObject子類

[英]You must register this ParseObject subclass before instantiating it

我在使用Parse Android應用程序中收到以下錯誤:

You must register this ParseObject subclass before instantiating it.

在我的Application對象中,我在onCreate執行以下操作:

Parse.enableLocalDatastore(this);
Parse.initialize(this, "code", "code");

那么為什么我仍然會收到此錯誤? 它昨天工作正常,但它突然停止工作。

這是我的清單文件:

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

您必須調用ParseObject.registerSubclass(YourClassName.class); 在調用Parse.initialize()之前。

此外,您需要注釋您的自定義類,如下所示:

@ParseClassName("YourClassName")
public class YourClassName extends ParseObject
{
}

最后,您的自定義類需要一個默認的無參數構造函數才能由ParseObject注冊。


參考: 子類化解析對象

你還必須把它放在你的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>

然后嘗試交換以下這些行

Parse.enableLocalDatastore(this);
Parse.initialize(this, "key", "key");

像這樣:

 Parse.initialize(this, "key", "key");
 Parse.enableLocalDatastore(this);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM