1

我将 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,它显示没有'title'的值,但数据库中存在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)
4

0 回答 0