簡體   English   中英

無法解析-Android

[英]Parsing isn't working - Android

我在數據庫函數中具有以下解析類以進行搜索,但是解析不起作用。 顯示“無法解析”的吐司。 再加上logcat沒有顯示任何錯誤,因此我無法指定導致烤面包片顯示的部分。

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;
    }
}

日志

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

您的Parser構造函數何時調用? 在調用異步任務之前,變量data,ctx和listView是否已初始化? 如果是這樣,則嘗試在當前try塊中記錄一些消息,因為似乎當前try塊內的語句甚至都沒有執行,並且直接跳轉以返回0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM