0

So I am making an Android app. Essentially what it does, is it fetches the user's longitude and latitude vid the network provider. It then passes that to a method which uses a geocoder to get back the zip code. Once I have the zip code, I make a request to WunderGround and get back the forecast a JSON. I then use GSON to parse it up, and get each Day's Date, Temp(F) and Conditions.

HOWEVER, my app keeps crashing, and I have no idea why. LogCat only tells me that it is in 'FutureTask'. I Googled that and it has something to do with threads, so I am assuming something in my Async is off.

If anyone can take a look at my code and give me some advice on how to fix this I would appreciate it.

CODE OMITTED (NO LONGER NECESSARY)

LOGCAT:

02-20 22:53:38.632: I/Adreno-EGL(31953): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build:  (CL4169980)
02-20 22:53:38.632: I/Adreno-EGL(31953): OpenGL ES Shader Compiler Version: 17.01.10.SPL
02-20 22:53:38.632: I/Adreno-EGL(31953): Build Date: 09/26/13 Thu
02-20 22:53:38.632: I/Adreno-EGL(31953): Local Branch: 
02-20 22:53:38.632: I/Adreno-EGL(31953): Remote Branch: 
02-20 22:53:38.632: I/Adreno-EGL(31953): Local Patches: 
02-20 22:53:38.632: I/Adreno-EGL(31953): Reconstruct Branch: 
02-20 22:53:42.846: E/dalvikvm(31953): Could not find class 'com.google.gson.JsonParser', referenced from method com.example.midterm2.MainActivity$parseJSON.doInBackground
02-20 22:53:42.846: W/dalvikvm(31953): VFY: unable to resolve new-instance 738 (Lcom/google/gson/JsonParser;) in Lcom/example/midterm2/MainActivity$parseJSON;
02-20 22:53:42.886: W/dalvikvm(31953): threadid=12: thread exiting with uncaught exception (group=0x417a0898)
02-20 22:53:42.936: E/AndroidRuntime(31953): FATAL EXCEPTION: AsyncTask #1
02-20 22:53:42.936: E/AndroidRuntime(31953): java.lang.RuntimeException: An error occured while executing doInBackground()
02-20 22:53:42.936: E/AndroidRuntime(31953):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.lang.Thread.run(Thread.java:841)
02-20 22:53:42.936: E/AndroidRuntime(31953): Caused by: java.lang.NoClassDefFoundError: com.google.gson.JsonParser
02-20 22:53:42.936: E/AndroidRuntime(31953):    at com.example.midterm2.MainActivity$parseJSON.doInBackground(MainActivity.java:197)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at com.example.midterm2.MainActivity$parseJSON.doInBackground(MainActivity.java:1)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-20 22:53:42.936: E/AndroidRuntime(31953):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-20 22:53:42.936: E/AndroidRuntime(31953):    ... 4 more
KyleCrowley
  • 900
  • 6
  • 14
  • 31
  • 2
    Post the logcat, please. That is a whole lot of code to sift through blindly. – codeMagic Feb 21 '14 at 03:52
  • Just looking at your code I can't find any problem in you AsyncTask execution, but are you executing another AsyncTask at the same time? This could cause a lot of strange problems...but as @codeMagic commented, please add your logcat – GhostDerfel Feb 21 '14 at 03:55
  • @codeMagic Posted. Please let me know if there is any more info you need. I am somewhat unfamiliar with logcat. – KyleCrowley Feb 21 '14 at 03:57
  • Did you try this? http://stackoverflow.com/questions/5694117/why-cant-android-find-com-google-gson-gson – user1406716 Feb 21 '14 at 03:59
  • [See this answer](http://stackoverflow.com/questions/9820675/gson-noclassdeffounderror-after-adt-and-sdk-tools-update-to-v17) – codeMagic Feb 21 '14 at 04:00
  • And [see this answer](http://stackoverflow.com/questions/18964329/eclipse-logcat-debugging/18964524#18964524) about reading logcat. – codeMagic Feb 21 '14 at 04:01
  • How you added gson.jar? Add latest version. find in below link https://code.google.com/p/google-gson/ – Gayathiri Feb 21 '14 at 04:04
  • @codeMagic Thank you for the answer. That was one of the causes. There was one more offending line but it was an easy fix after reading the logcat. Thanks again! – KyleCrowley Feb 21 '14 at 04:14
  • You are most welcome. You can upvote the answer(s) that helped solve the problem so they may help others easily – codeMagic Feb 21 '14 at 04:23

1 Answers1

0

According to the line that reads as

Caused by: java.lang.NoClassDefFoundError: com.google.gson.JsonParser
02-20 22:53:42.936: E/AndroidRuntime(31953):    at com.example.midterm2.MainActivity$parseJSON.doInBackground(MainActivity.java:197)

your GSON parser library isn't being packaged up in your APK properly. You should probably double check your dependency configuration.

I'm not sure how you have your project set up, but question: Libraries do not get added to APK anymore after upgrade to ADT 22 would probably be helpful.

Community
  • 1
  • 1
Jason
  • 2,617
  • 1
  • 16
  • 5