I am trying to use spring in my android app as client of my spring mvc REST application. I think I have a problem to put correct jars in classpath of my android app. I put the image of jars in libs folder of my android app. I found many related question on SO. But none of them helped me. That is why i am asking here again.
Here is how I am calling my webservice referenced from here :
#Override
protected SowResult doInBackground(Void... params) {
System.out.println("URLLLL : "+URL);
RestTemplate rest = new RestTemplate();
rest.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
SowResult result = rest.getForObject(URL, SowResult.class);
return result;
}
And the exception I am getting:
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.map.ObjectMapper.getTypeFactory
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.getJavaType(MappingJacksonHttpMessageConverter.java:166)
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.canRead(MappingJacksonHttpMessageConverter.java:101)
at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.doWithRequest(RestTemplate.java:542)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:474)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:237)
at com.inovarge.shoponway.resttasks.UserRestTask.doInBackground(UserRestTask.java:30)
at com.inovarge.shoponway.resttasks.UserRestTask.doInBackground(UserRestTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
The exception indicates that you are missing a required Jackson dependency. First, I recommend using MappingJackson2HttpMessageConverter instead of the MappingJacksonHttpMessageConverter which you've configured:
rest.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
Next, MappingJackson2HttpMessageConverter depends on the Jackson 2 library for its functionality, which requires the following files be on your classpath:
jackson-databind-2.3.2.jar
jackson-annotations-2.3.2.jar
jackson-core-2.3.2.jar
You already have jackson-databind-2.3.2.jar in your libs folder, so you need to download the other two jars.
Lastly, I highly recommend using a dependency management system like the Gradle plugin in Android's New Build System. It will handle downloading all the transitive dependencies for you instead of having to manually do that.
Related
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.mime.HttpMultipartMode
at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:91)
at com.greencubes.greendesk.AndroidMultiPartEntity.<init>(AndroidMultiPartEntity.java:19)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.uploadFile(FirstFragment.java:244)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.doInBackground(FirstFragment.java:233)
at com.greencubes.greendesk.FirstFragment$UploadFileToServer.doInBackground(FirstFragment.java:211)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
If you are using a library, you need to put it into /libs folder.
download httpmime, httpcore and httpclient library from http://hc.apache.org/downloads.cgi
Hope this will help as i have the same jar files in the studio.
If you are using Eclipse then add all the jar files to build path.
Thanks,
Apache HTTP client was removed in Lollipop. It's recommended to use HttpUrlConnection instead.
If you have to use it you can add:
android {
useLibrary 'org.apache.http.legacy'
}
to your build.gradle file.
I am getting this issue most of the time in samsung devices while sending sms.
Android version
Android 4.0.3 - 4.0.4
This is the error report I'm getting
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1333)
at android.os.Parcel.readException(Parcel.java:1281)
at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:644)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:149)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:99)
at com.msh7.utilities.SMSSender$SMSProgressTask.doInBackground(SMSSender.java:87)
at com.msh7.utilities.SMSSender$SMSProgressTask.doInBackground(SMSSender.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
On line 87, I have this code
sms.sendTextMessage(destinationNumber, null, msg, sentPI, deliveredPI);
and all this method is inside the AsyncTask's doInBackground() method.
Could anyone please help me in this?
*Note : My App sends sms in the background and it's not a default sms app.
I guess it's due to over size limit of text. Max allowed characters are 159. So you have to divide message into parts and send it.
Dude you are getting NullPointerException. Seems like you have not initialized sms object.
Please check..
Sorry if this sound newb but.. =[
Im working with an application which need to load a large amount of images onto a textview, i didnt use webview becuz sometimes it doesnt lead to mobile view so i decide to parse the content and use html.fromHtml to show it to the Textview.
Problem is:
if i load a page is luckily there not much images, it run pretty smooth.
otherwise it get the error like below...
anyone know if theres a way that i can dispose the source from the system memory after it finished reading the image?...or...any other way will fix my problem?
i used the source from here Android ImageGetter images overlapping text
05-08 21:30:31.404: ERROR/dalvikvm-heap(25083): Out of memory on a 1920016-byte allocation.
05-08 21:30:31.404: ERROR/AndroidRuntime(25083): FATAL EXCEPTION: AsyncTask #10
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
at android.graphics.drawable.Drawable.createFromStream(Drawable.java:741)
at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.fetchDrawable(URLImageParser.java:90)
at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.doInBackground(URLImageParser.java:58)
at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.doInBackground(URLImageParser.java:48)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
05-08 21:30:31.504: ERROR/dalvikvm-heap(25083): Out of memory on a 1920016-byte allocation.
Check out this post, it uses the example of getting picutres from the SD Card/Gallery for how to downsample images so that you avoid this problem. Its a pretty easy fix.
I have a live app that uses AsyncTask in several activities, and I'm getting an untraceable error (below). The key line of bto.org.monitoring.birdtrack.ce.doInBackground(Unknown Source) that is being sent to Google Play by my users (with no messages of course) isn't letting me debug this problem, so I can't find the right bit of code never mind post it here. Any ideas?
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.NullPointerException
at bto.org.monitoring.birdtrack.ce.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
... 4 more
OK, sussed this now. I am using Proguard, and can detect the location of the doInBackground() method by grabbing the error and running it past the using:
retrace.sh -verbose myApp/proguard/mapping.txt myErrorFile.txt
This translates the error to display the classes that are causing it. Hooray!
Disclaimer...I think I've gone through all of the related posts on this topic and so far, none of them have fixed my problem. That being said, if I missed something, feel free to point me in the proper direction.
Environment:
-newly configured Eclipse Indigo
-ADT 18
-GWT 2.4
-App Engine SDK 1.6.4
I'm attempting to create a standard, no frills boilerplate "App Engine Connected Android Project" to begin learning how things are handled between App Engine and Android.
After completing the File > New > App Engine Connected Android project (with a functional C2DM role email and password) I get the MyTasks-Android and MyTasks-AppEngine projects in Eclipse.
Knowing the whole lib versus libs issue with ADT17+, I change the lib folder in the MyTasks-Android project to libs and update the build path for the three jars (c2dm.jar, requestfactory-client.jar and validation-api-1.0.0.GA.jar). I also add the MyTasks-AppEngine project to the build path.
Once that's all done, I try to run the App-Android project on my device.
I am able to select my Android account, "allow" it to access my account and I see the "say hello" button. Upon clicking the button, I get the following error in Eclipse:
05-01 22:13:22.965: E/dalvikvm(17457): Could not find class 'com.mytasks.client.MyRequestFactory', referenced from method com.mytasks.MyTasksActivity$2$1.doInBackground
05-01 22:13:22.965: W/dalvikvm(17457): VFY: unable to resolve const-class 315 (Lcom/mytasks/client/MyRequestFactory;) in Lcom/mytasks/MyTasksActivity$2$1;
05-01 22:13:22.965: D/dalvikvm(17457): VFY: replacing opcode 0x1c at 0x000a
05-01 22:13:22.973: W/dalvikvm(17457): threadid=11: thread exiting with uncaught exception (group=0x40a291f8)
05-01 22:13:22.989: E/AndroidRuntime(17457): FATAL EXCEPTION: AsyncTask #1
05-01 22:13:22.989: E/AndroidRuntime(17457): java.lang.RuntimeException: An error occured while executing doInBackground()
05-01 22:13:22.989: E/AndroidRuntime(17457): at android.os.AsyncTask$3.done(AsyncTask.java:278)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.lang.Thread.run(Thread.java:856)
05-01 22:13:22.989: E/AndroidRuntime(17457): Caused by: java.lang.NoClassDefFoundError: com.mytasks.client.MyRequestFactory
05-01 22:13:22.989: E/AndroidRuntime(17457): at com.mytasks.MyTasksActivity$2$1.doInBackground(MyTasksActivity.java:145)
05-01 22:13:22.989: E/AndroidRuntime(17457): at com.mytasks.MyTasksActivity$2$1.doInBackground(MyTasksActivity.java:1)
05-01 22:13:22.989: E/AndroidRuntime(17457): at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-01 22:13:22.989: E/AndroidRuntime(17457): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
I've been working on this all day and so far, no luck. So, if anyone has any suggestions, I would definitely appreciate the assistance.
Thanks!
EDIT - 5/2/2012 - added setHelloWorldScreenContent from MyTasksActivity class. Specifically, failing at: MyRequestFactory requestFactory = Util.getRequestFactory(mContext, MyRequestFactory.class);
Again, this is a vanilla wizard-generated App Engine Connected Android project - the only change I made was adding the MyTasks-AppEngine to the MyTasks-Android build path and changing lib to libs, then readding the three jars to the build path.
private void setHelloWorldScreenContent() {
setContentView(R.layout.hello_world);
final TextView helloWorld = (TextView) findViewById(R.id.hello_world);
final Button sayHelloButton = (Button) findViewById(R.id.say_hello);
sayHelloButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sayHelloButton.setEnabled(false);
helloWorld.setText(R.string.contacting_server);
// Use an AsyncTask to avoid blocking the UI thread
new AsyncTask<Void, Void, String>() {
private String message;
#Override
protected String doInBackground(Void... arg0) {
MyRequestFactory requestFactory = Util.getRequestFactory(mContext, MyRequestFactory.class);
final HelloWorldRequest request = requestFactory.helloWorldRequest();
Log.i(TAG, "Sending request to server");
request.getMessage().fire(new Receiver<String>() {
#Override
public void onFailure(ServerFailure error) {
message = "Failure: " + error.getMessage();
}
#Override
public void onSuccess(String result) {
message = result;
}
});
return message;
}
#Override
protected void onPostExecute(String result) {
helloWorld.setText(result);
sayHelloButton.setEnabled(true);
}
}.execute();
}
});
}
I faced the same issue. I also just changed the folder name from lib to libs and added back the 3 jars in build path in andorid project and it worked.
I just spent 4 hours on it, the standard lib->libs didnt help me, at the end the solution was compile with jdk 1.6 not 1.7, it means you have to compile even the shared libraries from appengine (well logically) compile with 1.6