Overcome out of memory Error when loading images into textview - android

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.

Related

image upload using android multipart than getting error in old version

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.

"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

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.

Untracable AsyncTask error

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!

Categories

Resources