0

我正在使用 android 创建一个列表来添加任务,当我运行它并启动模拟器时有很多错误。我努力解决它们,但我不能,我认为一个类中的问题是它应该显示所有任务的主要问题

这是原木猫

04-08 08:53:43.334: E/Trace(637): error opening trace file: No such file or directory (2)
04-08 08:53:45.043: I/Choreographer(637): Skipped 54 frames!  The application may be doing too much work on its main thread.
04-08 08:53:45.144: D/gralloc_goldfish(637): Emulator without GPU emulation detected.
04-08 08:53:45.479: I/Choreographer(637): Skipped 35 frames!  The application may be doing too much work on its main thread.
04-08 08:53:46.067: I/Choreographer(637): Skipped 56 frames!  The application may be doing too much work on its main thread.
04-08 08:53:46.713: D/dalvikvm(637): GC_CONCURRENT freed 132K, 2% free 9089K/9268K, paused 9ms+3ms, total 102ms
04-08 08:53:46.803: E/JSON Parser(637): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
04-08 08:53:46.843: W/dalvikvm(637): threadid=11: thread exiting with uncaught exception (group=0x2bd39930)
04-08 08:53:46.903: E/AndroidRuntime(637): FATAL EXCEPTION: AsyncTask #1
04-08 08:53:46.903: E/AndroidRuntime(637): java.lang.RuntimeException: An error occured while executing doInBackground()
04-08 08:53:46.903: E/AndroidRuntime(637):  at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.lang.Thread.run(Thread.java:856)
04-08 08:53:46.903: E/AndroidRuntime(637): Caused by: java.lang.NullPointerException
04-08 08:53:46.903: E/AndroidRuntime(637):  at com.example.checklist.MainTask$LoadAllTasks.doInBackground(MainTask.java:172)
04-08 08:53:46.903: E/AndroidRuntime(637):  at com.example.checklist.MainTask$LoadAllTasks.doInBackground(MainTask.java:1)
04-08 08:53:46.903: E/AndroidRuntime(637):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 08:53:46.903: E/AndroidRuntime(637):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-08 08:53:46.903: E/AndroidRuntime(637):  ... 3 more
04-08 08:53:51.744: E/WindowManager(637): Activity com.example.checklist.MainTask has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c607c90 V.E..... R.....ID 0,0-684,192} that was originally added here
04-08 08:53:51.744: E/WindowManager(637): android.view.WindowLeaked: Activity com.example.checklist.MainTask has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{2c607c90 V.E..... R.....ID 0,0-684,192} that was originally added here
04-08 08:53:51.744: E/WindowManager(637):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
04-08 08:53:51.744: E/WindowManager(637):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
04-08 08:53:51.744: E/WindowManager(637):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.Dialog.show(Dialog.java:281)
04-08 08:53:51.744: E/WindowManager(637):   at com.example.checklist.MainTask$LoadAllTasks.onPreExecute(MainTask.java:155)
04-08 08:53:51.744: E/WindowManager(637):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
04-08 08:53:51.744: E/WindowManager(637):   at android.os.AsyncTask.execute(AsyncTask.java:534)
04-08 08:53:51.744: E/WindowManager(637):   at com.example.checklist.MainTask.onCreate(MainTask.java:79)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.Activity.performCreate(Activity.java:5104)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-08 08:53:51.744: E/WindowManager(637):   at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 08:53:51.744: E/WindowManager(637):   at android.os.Looper.loop(Looper.java:137)
04-08 08:53:51.744: E/WindowManager(637):   at android.app.ActivityThread.main(ActivityThread.java:5039)
04-08 08:53:51.744: E/WindowManager(637):   at java.lang.reflect.Method.invokeNative(Native Method)
04-08 08:53:51.744: E/WindowManager(637):   at java.lang.reflect.Method.invoke(Method.java:511)
04-08 08:53:51.744: E/WindowManager(637):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-08 08:53:51.744: E/WindowManager(637):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-08 08:53:51.744: E/WindowManager(637):   at dalvik.system.NativeStart.main(Native Method)
04-08 08:53:51.744: I/Choreographer(637): Skipped 49 frames!  The application may be doing too much work on its main thread.
04-08 08:53:57.493: I/Process(637): Sending signal. PID: 637 SIG: 9
4

1 回答 1

0

考虑到您的日志显示 json 解析错误,然后是 NPE,我的猜测是问题发生在这里:

// getting JSON string from URL 
JSONObject json = jParser.makeHttpRequest(url_all_tasks, "GET", params); 

// Check your log cat for JSON reponse 
Log.d("All Tasks: ", json.toString());

看起来解析器失败并且只返回nullfor json,然后调用json.toString()失败并出现 NPE。

AsyncTask此外,您应该根据 Sunil Havnur 给出的评论更改您的代码。

于 2013-04-08T18:22:51.150 回答