0

I'm working on android to create a list to add tasks , there are many error when I run it and the emulator started. I tried hard to solve them but I couldn't and I think the problem in one class which is the main it supposed to display all tasks

here is the log cat

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
Najd
  • 78
  • 1
  • 7
  • The code in this is very similar to http://stackoverflow.com/questions/13295875/start-activity-in-doinbackground-method Consider adding a comment to that – Arun C Apr 08 '13 at 09:11
  • 1
    Caused by: java.lang.NullPointerException at line number 172. What is that line? – Kanth Apr 08 '13 at 09:14
  • 1
    Good way to avoid NullPointer exception would be Check that object is null or not. then do getter or setter operation. some this like this if (object!= null) { //do something with that object }. this way you can avoid crashing due to null pointer exception. – RockandRoll Apr 08 '13 at 09:26
  • 1
    Dont start any activity in the background thread. that also causes application to crash. do all the UI operation in OnPostexecute method. – RockandRoll Apr 08 '13 at 09:29
  • 1
    OnpostExecute Method will be Run On main Thread, then why are you setting adapter again in RunOnMainThread? it is just an OverHead task. – RockandRoll Apr 08 '13 at 09:32

1 Answers1

0

Considering that your log shows json parsing error followed by an NPE, my guess is that the issue happens here:

// 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());

Looks like parser fails and just returns null for json, and then calling json.toString() fails with an NPE.

Also you should change your AsyncTask code as to comments given by Sunil Havnur.

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91