I am using Parse with back4app so my app supports LiveQuery, however the LiveQuery throws an exception.
What I have tried,
-JSONObject.optString (It does not work)
Here's my code,
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;
}
}
Here's the Logcat which shows that there is no value of 'title' but the value of title exists in the database and the code can access it when I refresh the data manually:
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)