I have the following parse class for a search in the database function, but parsing isn't working. "Unable to parse" toast is showing. Plus logcat isn't showing any errors, so I can't specify which part is causing the toast to show.
public class Parser extends AsyncTask <Void, Void,Integer> {
Context ctx;
String data;
ListView listView;
ArrayList<String> titles = new ArrayList<>();
public Parser (Context ctx, String data, ListView listView){
this.ctx=ctx;
this.data=data;
this.listView=listView;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Integer doInBackground(Void... params) {
return this.parse();
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
if (integer == 1){
ArrayAdapter adapter = new ArrayAdapter(ctx, android.R.layout.simple_list_item_1, titles);
listView.setAdapter(adapter);
}else {
Toast.makeText(ctx, "Unable to Parse", Toast.LENGTH_LONG).show();
}
}
private int parse (){
try {
JSONArray ja = new JSONArray(data);
JSONObject jo = null;
titles.clear();
for (int i = 0; i < ja.length(); i++){
jo=ja.getJSONObject(i);
String title = jo.getString("post_title");
titles.add(title);
}
return 1;
} catch (JSONException e) {
e.printStackTrace();
}
return 0;
}
}
log
03-17 19:09:53.246 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-17 19:09:53.306 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-17 19:09:53.446 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: MSG_RESIZED: ci=Rect(0, 96 - 0, 1128) vi=Rect(0, 96 - 0, 1128) or=1
03-17 19:09:54.296 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{145fd86 V.E...... R.....I. 0,0-0,0}
03-17 19:09:54.306 13705-14599/com.example.joudialfattal.skillsexchange I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-17 19:09:54.306 13705-14599/com.example.joudialfattal.skillsexchange I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-17 19:09:54.306 13705-13705/com.example.joudialfattal.skillsexchange W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-17 19:09:54.326 13705-13733/com.example.joudialfattal.skillsexchange D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1592x909]-format:1
03-17 19:09:54.336 13705-13705/com.example.joudialfattal.skillsexchange W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-17 19:09:54.376 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-17 19:09:54.616 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: #3 mView = null
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: org.json.JSONException: End of input at character 0 of
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at org.json.JSONArray.<init>(JSONArray.java:92)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at org.json.JSONArray.<init>(JSONArray.java:108)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at com.example.joudialfattal.skillsexchange.Parser.parse(Parser.java:58)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at com.example.joudialfattal.skillsexchange.Parser.doInBackground(Parser.java:39)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at com.example.joudialfattal.skillsexchange.Parser.doInBackground(Parser.java:18)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
03-17 19:09:54.636 13705-14614/com.example.joudialfattal.skillsexchange W/System.err: at java.lang.Thread.run(Thread.java:818)
03-17 19:09:54.696 13705-13705/com.example.joudialfattal.skillsexchange E/ViewRootImpl: sendUserActionEvent() mView == null
03-17 19:09:54.706 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: #1 mView = android.widget.LinearLayout{864f1d1 V.E...... ......I. 0,0-0,0}
03-17 19:09:54.766 13705-13733/com.example.joudialfattal.skillsexchange D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [637x181]-format:1
03-17 19:09:54.776 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-17 19:09:54.776 13705-13705/com.example.joudialfattal.skillsexchange W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-17 19:09:54.806 13705-13733/com.example.joudialfattal.skillsexchange V/RenderScript: 0x7f690b1000 Launching thread(s), CPUs 8
03-17 19:09:58.206 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: #3 mView = null
03-17 19:10:28.296 13705-13705/com.example.joudialfattal.skillsexchange W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-17 19:10:28.346 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
03-17 19:10:28.516 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
03-17 19:10:28.606 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
03-17 19:10:28.606 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
03-17 19:10:28.606 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
03-17 19:10:28.676 13705-13705/com.example.joudialfattal.skillsexchange V/ActivityThread: updateVisibility : ActivityRecord{6fcff37 token=android.os.BinderProxy@267e99f {com.example.joudialfattal.skillsexchange/com.example.joudialfattal.skillsexchange.FindSkill}} show : true
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
03-17 19:10:28.716 13705-13705/com.example.joudialfattal.skillsexchange W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
03-17 19:10:29.176 13705-13705/com.example.joudialfattal.skillsexchange D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1