Thursday, April 11, 2013

[android help] AsyncTask with readObject()

android - AsyncTask with readObject() - Stack Overflow



















util.concurrent.FutureTask.finishCompletion when i try to open a file in internal storage i don't know how to handle that if you have some advices help me please


My code:



protected String doInBackground(Hashtable... params) {
Hashtable ht=params[0];

String json=HelperHttp.getJSONResponseFromURL(url, ht);
System.out.println(json);

//some code

if(json!=null) {try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(new File(getCacheDir(),"")+"cacheFile.srl")));
/*The problem is here*/ JSONObject jsonObject = (JSONObject) in.readObject();
in.close();


The stacktrace:


04-11 11:52:04.694: E/AndroidRuntime(1026): FATAL EXCEPTION: AsyncTask #1 04-11 11:52:04.694: E/AndroidRuntime(1026): java.lang.RuntimeException: An error occured while executing doInBackground() 04-11 11:52:04.694: E/AndroidRuntime(1026): at android.os.AsyncTask$3.done(AsyncTask.java:299) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.lang.Thread.run(Thread.java:856) 04-11 11:52:04.694: E/AndroidRuntime(1026): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject 04-11 11:52:04.694: E/AndroidRuntime(1026): at com.cgi.activity.ActivityListNews$GetDeptAyncTask.doInBackground(ActivityListNews.java:81) 04-11 11:52:04.694: E/AndroidRuntime(1026): at com.cgi.activity.ActivityListNews$GetDeptAyncTask.doInBackground(ActivityListNews.java:1) 04-11 11:52:04.694: E/AndroidRuntime(1026): at android.os.AsyncTask$2.call(AsyncTask.java:287) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 04-11 11:52:04.694: E/AndroidRuntime(1026): ... 3 more



















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...