1

我正在开发一个使用 Kinvey 作为后端的应用程序。我遇到的问题是,当我调用 kinvey appData 请求时,控件不会进入 kinvey 调用的 onsuccess 方法并返回到调用方法的位置。这是我的主类,我正在调用一个函数,该函数具有 kinvey 客户端调用来获取数据。

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_image_list);
    // kinvey login here//

     // here is the function that fetch my data from kinvey
     GetAllCategory();

    imageUrls=urls // this is the assignment that cause Null pointer Exception

    }

现在这是我的 GetAllCategories 函数

        public void GetAllCategory(){
       AsyncAppData<EntityCategories> myEvents=mKinveyClient.appData("categories",  EntityCategories.class);                                      
       myEvents.get(new Query(), new KinveyListCallback<EntityCategories>(){
       @Override
        public void onFailure(Throwable error) {
            // TODO Auto-generated method stub
            Log.e(TAG, "failed to save event data", error);
        }

        @Override
        public void onSuccess(EntityCategories[] result1) {
            // TODO Auto-generated method stub

        //  Log.e(TAG,"Name is "+result1[0].get("name"));
        //  Log.e(TAG,"type is"+result1[0].get("type"));

            categories=result1;
            //onPrintCategoryClick();
        for(int i=0;i<categories.length;i++){

            imageUrls[i]=(String) categories[i].get("icon");

        }

        }


    });
    }

但是在执行 kinvey 调用后控制权会返回到 oncreate 方法,并且不要转到 onSuccess 方法。执行整个 oncreate 方法后,它会返回到 onSuccess。但在此之前,由于 NUll 指针异常,应用程序崩溃了。

请原谅我的格式不好,请问您是否需要我解释更多。预先感谢

4

1 回答 1

0

迟到的答案,但以防万一有人来找:

从名称中可以清楚地看出 - AsyncAppData,用于获取数据的 Kinvey 调用是异步执行的。

最好的办法是在 onSuccess 方法中分配 url。在此之前,您应该显示一个进度对话框,让用户知道发生了什么。

于 2015-07-28T06:14:24.953 回答