image upload using android multipart than getting error in old version - android

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.

Related

"Can't compress a recycled bitmap" - but I don't use any Bitmaps

I'm getting error "Can't compress a recycled bitmap", but in my app I don't use bitmaps (not directly). I have only logo on main screen, and one icon, from drawables (*.png files), but I also use AdMob ads (maybe this is the cause).
Problem occurred not on my phone (Android v: 4.1.2), so I have limited details about that, below is stack trace:
0 java.lang.RuntimeException: An error occured while executing doInBackground()
1 at android.os.AsyncTask$3.done(AsyncTask.java:299)
2 at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
3 at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
4 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
5 at java.util.concurrent.FutureTask.run(FutureTask.java:137)
6 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
7 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
8 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
9 at java.lang.Thread.run(Thread.java:856)
10 Caused by: java.lang.IllegalStateException: Can't compress a recycled bitmap
11 at android.graphics.Bitmap.checkRecycled(Bitmap.java:239)
12 at android.graphics.Bitmap.compress(Bitmap.java:764)
13 at com.instabug.library.internal.storage.r.a(SaveBitmapTask.java:43)
14 at com.instabug.library.internal.storage.r.doInBackground(SaveBitmapTask.java:17)
15 at android.os.AsyncTask$2.call(AsyncTask.java:287)
16 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
17 ... 5 more
Can I sand any more informations about it?
Any suggestions will be appreciated

java.lang.VerifyError when using OkHttp

I use this code in my android studio project:
HttpUrl url = new HttpUrl.Builder().scheme("http").host("www.somesite.com")
.addPathSegment("kontakt")
.addQueryParameter("yit_contact[imie]", name)
.addQueryParameter("yit_contact[email]", email)
.addQueryParameter("yit_contact[telefon]", telephone)
.addQueryParameter("yit_contact[wiadomosc]", message)
.addQueryParameter("yit_bot", "")
.addQueryParameter("_wp_http_referer", "/kontakt/").build();
Request request = new Request.Builder().url(url).build();
Response response = new OkHttpClient().newCall(request).execute();
and I get this error when I try to get Response object:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.VerifyError: com/squareup/okhttp/internal/http/HttpConnection$AbstractSource
at com.squareup.okhttp.internal.http.HttpConnection.newFixedLengthSource(HttpConnection.java:246)
at com.squareup.okhttp.internal.http.HttpTransport.getTransferStream(HttpTransport.java:125)
at com.squareup.okhttp.internal.http.HttpTransport.openResponseBody(HttpTransport.java:110)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:926)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
at com.squareup.okhttp.Call.getResponse(Call.java:274)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
at com.squareup.okhttp.Call.execute(Call.java:81)
at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:135)
at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:87)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:856)
I have added jar files to project:
compile files('libs/okhttp-2.4.0.jar')
compile files('libs/okio-1.0.0.jar')
Help.
Try adding Okio-1.4.0, which is required by OkHttp 2.4.0.
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.4.0</version>
</dependency>

SMS Sending issues in android kitkat

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..

How to use spring in Android Application?

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.

Overcome out of memory Error when loading images into textview

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.

Categories

Resources