org.json.JSONException:没有title的值(PARSE with BACK4APP)

时间:2017-02-16 18:33:23

标签: json parse-platform livequery back4app

我正在使用Parse和back4app,所以我的应用程序支持LiveQuery,但是LiveQuery会引发异常。

我尝试了什么,

-JSONObject.optString(它不起作用)

这是我的代码,

public class Live extends AsyncTask<String , Void, String>{
    @Override
    protected String doInBackground(String... params) {

        // Subscription
        final Subscription sub = new BaseQuery.Builder("Invited")
                .where("username", ParseUser.getCurrentUser().getUsername())
                .addField("title")
                .build()
                .subscribe();


        sub.on(LiveQueryEvent.CREATE, new OnListener() {
            @Override
            public void on(final JSONObject object) {


                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            try {
                                titles.add(object.getString("title"));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                            adapter.notifyDataSetChanged();
                        }
                    });




                // Action to be executed here when an object that matches
                // The filter you set up
            }
        });


        return null;
    }
}

这里是Logcat,它显示没有&#39; title&#39;但是title的值存在于数据库中,当我手动刷新数据时,代码可以访问它:

02-16 23:24:37.761 24536-24536/com.hamza.meetme W/System.err:       org.json.JSONException: No value for title
02-16 23:24:37.761 24536-24536/com.hamza.meetme W/System.err:     at org.json.JSONObject.get(JSONObject.java:389)
02-16 23:24:37.761 24536-24536/com.hamza.meetme W/System.err:     at org.json.JSONObject.getString(JSONObject.java:550)
02-16 23:24:37.761 24536-24536/com.hamza.meetme W/System.err:     at com.hamza.meetme.LoggedIn$Live$1$1.run(LoggedIn.java:110)
02-16 23:24:37.761 24536-24536/com.hamza.meetme W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at android.os.Looper.loop(Looper.java:148)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-16 23:24:37.762 24536-24536/com.hamza.meetme W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

0 个答案:

没有答案