OutOfMemoryError problems - android - android

my app (memory game) is using various images. In my /drawable/ folder are about ~50 .png images with 252x252 size. My app has some levels, for example 4x3, 4x6 etc. After 3-4 games (for example, I started from 2x2 to 4x6) - my app is crashing (Unfortunately, your app has stopped). In LogCat I have these errors:
04-16 23:05:35.382: E/AndroidRuntime(13622): FATAL EXCEPTION: main
04-16 23:05:35.382: E/AndroidRuntime(13622): java.lang.OutOfMemoryError
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.Bitmap.nativeCreate(Native Method)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:530)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:505)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:357)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:777)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.content.res.Resources.loadDrawable(Resources.java:1940)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.content.res.Resources.getDrawable(Resources.java:669)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.view.View.setBackgroundResource(View.java:11861)
04-16 23:05:35.382: E/AndroidRuntime(13622): at com.example.testlogo.MainActivity.onCreate(MainActivity.java:145)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.Activity.performCreate(Activity.java:4465)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.os.Looper.loop(Looper.java:137)
04-16 23:05:35.382: E/AndroidRuntime(13622): at android.app.ActivityThread.main(ActivityThread.java:4448)
04-16 23:05:35.382: E/AndroidRuntime(13622): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 23:05:35.382: E/AndroidRuntime(13622): at java.lang.reflect.Method.invoke(Method.java:511)
04-16 23:05:35.382: E/AndroidRuntime(13622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
04-16 23:05:35.382: E/AndroidRuntime(13622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
04-16 23:05:35.382: E/AndroidRuntime(13622): at dalvik.system.NativeStart.main(Native Method)
As I said, I am using images from /drawable/ folder. To make for example 4x3 level, I am using GridLayout and ImageButtons. I have a method, which randomizes ImageButton's place and then I am putting the image to the ImageButton, like this:
button1.setImageResource(R.drawable.logo);
For resize my ImageButton I am using:
Display display = getWindowManager().getDefaultDisplay();
int screenwidth = display.getWidth();
int screenheight = display.getHeight();
button.setMaxHeight(screenwidth/3);
button.setMaxWidth(screenwidth/3);
So I do not really know, how to manage with my problem. Maybe should I use Bitmap instead of ImageResource?
Note:
1)Every level have own class, they are very similar to each other.
2)Every level class have 24 images. If the level is 4x3 I will get first random 6 pics.
3)Every activity are using finish(); method if the activity is closed/onBackPressed.
int[] img ={R.drawable.cherry90,R.drawable.apple90,R.drawable.applered90,R.drawable.apricot90,R.drawable.banana90,R.drawable.blueberry90,
R.drawable.coconut90,R.drawable.gooseberry90,R.drawable.grape90,R.drawable.grapefruit90,R.drawable.kiwi90,R.drawable.lemon90,
R.drawable.lime90,R.drawable.mandarin90,R.drawable.mango90,R.drawable.melon,R.drawable.papaya90,R.drawable.peach90,
R.drawable.pears90,R.drawable.pineapple,R.drawable.plums90,R.drawable.pomegranate90,R.drawable.raspberry90,R.drawable.strawberry90};
I hope you will understand what I wanted to say. I were searching an answer to this problem, but did not find.

Basically it an error that indicates you have used excess of your ram memory allocations, there is nothing wrong in your code it just needs to be optimized.
Here are a few ways to do this:
Reduce the resolution of the images, you can still stretch them to the same size, but they wont show in as much detail.
Delete or re-use image variable space.
If you show the same image multiple times on the screen, like with most tiled maps. only create one variable where the image is stored.
Remember variables mean ram.

Related

OpenCV on Android without OpenCV Manager

I know that my question was asked before.
But no solution is working for me.
For now I tried this solutions:
Solution 1
Solution 2
Solution 3
Solution 4
But no one of them worked for me.
My application project include a JNI part so I added all the mentioned line from THIS tutorial to the Android.mk file,
I comment this line :
if(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback));
And added:
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
After public void onResume()
My application gets stuck and crushed when the OpenCV started.
This is the LogCat output:
04-16 10:00:25.020: W/System.err(14797): java.io.FileNotFoundException: /storage/emulated/0/DCIM/Frames/20140416_100025.mp4: open failed: ENOENT (No such file or directory)
04-16 10:00:25.020: W/System.err(14797): at libcore.io.IoBridge.open(IoBridge.java:409)
04-16 10:00:25.020: W/System.err(14797): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
04-16 10:00:25.020: W/System.err(14797): at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
04-16 10:00:25.020: W/System.err(14797): at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
04-16 10:00:25.025: W/System.err(14797): at android.media.MediaRecorder.prepare(MediaRecorder.java:776)
04-16 10:00:25.025: W/System.err(14797): at com.example.homedevice.SampleTestingAct.prepareRecorder(SampleTestingAct.java:371)
04-16 10:00:25.025: W/System.err(14797): at com.example.homedevice.SampleTestingAct.StartTest(SampleTestingAct.java:443)
04-16 10:00:25.025: W/System.err(14797): at com.example.homedevice.SampleTestingAct.access$0(SampleTestingAct.java:420)
04-16 10:00:25.025: W/System.err(14797): at com.example.homedevice.SampleTestingAct$2$1.run(SampleTestingAct.java:2037)
04-16 10:00:25.025: W/System.err(14797): at java.util.Timer$TimerImpl.run(Timer.java:284)
04-16 10:00:25.025: W/System.err(14797): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
04-16 10:00:25.025: W/System.err(14797): at libcore.io.Posix.open(Native Method)
04-16 10:00:25.030: W/System.err(14797): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
04-16 10:00:25.030: W/System.err(14797): at libcore.io.IoBridge.open(IoBridge.java:393)
04-16 10:00:25.030: W/System.err(14797): ... 9 more
04-16 10:00:25.260: E/MediaRecorder(14797): start called in an invalid state: 4
04-16 10:00:25.260: W/dalvikvm(14797): threadid=16: thread exiting with uncaught exception (group=0x41c44700)
04-16 10:00:25.260: E/AndroidRuntime(14797): FATAL EXCEPTION: Timer-2
04-16 10:00:25.260: E/AndroidRuntime(14797): java.lang.IllegalStateException
04-16 10:00:25.260: E/AndroidRuntime(14797): at android.media.MediaRecorder.start(Native Method)
04-16 10:00:25.260: E/AndroidRuntime(14797): at com.example.homedevice.SampleTestingAct.StartTest(SampleTestingAct.java:445)
04-16 10:00:25.260: E/AndroidRuntime(14797): at com.example.homedevice.SampleTestingAct.access$0(SampleTestingAct.java:420)
04-16 10:00:25.260: E/AndroidRuntime(14797): at com.example.homedevice.SampleTestingAct$2$1.run(SampleTestingAct.java:2037)
04-16 10:00:25.260: E/AndroidRuntime(14797): at java.util.Timer$TimerImpl.run(Timer.java:284)
04-16 10:00:32.555: I/Choreographer(14797): Skipped 436 frames! The application may be doing too much work on its main thread.
04-16 10:00:32.715: E/ViewSystem(14797): ViewRootImpl #2 Surface is not valid.
04-16 10:00:32.725: E/MediaRecorder(14797): stop called in an invalid state: 4
04-16 10:00:32.725: D/AndroidRuntime(14797): Shutting down VM
04-16 10:00:32.725: W/dalvikvm(14797): threadid=1: thread exiting with uncaught exception (group=0x41c44700)
04-16 10:00:32.730: I/Process(14797): Sending signal. PID: 14797 SIG: 9
04-16 10:00:33.060: D/dalvikvm(15019): GC_FOR_ALLOC freed 56K, 12% free 9605K/10840K, paused 13ms, total 14ms
04-16 10:00:33.060: I/dalvikvm-heap(15019): Grow heap (frag case) to 11.604MB for 1127536-byte allocation
04-16 10:00:33.080: D/dalvikvm(15019): GC_FOR_ALLOC freed <1K, 11% free 10706K/11944K, paused 20ms, total 20ms
04-16 10:00:33.115: D/dalvikvm(15019): GC_FOR_ALLOC freed <1K, 10% free 11593K/12832K, paused 11ms, total 11ms
04-16 10:00:33.200: D/libEGL(15019): loaded /system/lib/egl/libEGL_mali.so
04-16 10:00:33.200: D/libEGL(15019): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-16 10:00:33.205: D/libEGL(15019): loaded /system/lib/egl/libGLESv2_mali.so
04-16 10:00:33.210: E/(15019): Device driver API match
04-16 10:00:33.210: E/(15019): Device driver API version: 23
04-16 10:00:33.210: E/(15019): User space API version: 23
04-16 10:00:33.210: E/(15019): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct 9 21:05:57 KST 2013
04-16 10:00:33.265: D/OpenGLRenderer(15019): Enabling debug mode 0
Is it possible to work with OpenCV without the OpenCV manager(maybe include him in my app?)
Hope that someone can help here.
Thanks!
sure you can do that. You just need to have the specific OpenCV libraries packed in your APK. Have a look at my reply here.

Desire2Learn Connection via Android

I am trying to connect to d2l via android. (I normally use C# but have decided to try an android application).
I have tried using the java client library compiling it and putting the .jar file into my libs folder with in the android project but the app crashes whenever I try to create an authenticated URI.
Anyone have any ideas? tips? I've searched for an example but haven't found one yet.
Thanks!
There is nothing being output to the console but this is what I get in the Logs hopefully this is what you're looking for:
04-16 17:05:39.690: W/dalvikvm(2118): VFY: unable to resolve static method 3861: Lorg/apache/commons/codec/binary/Base64;.encodeBase64 ([BZZ)[B
04-16 17:05:39.690: D/dalvikvm(2118): VFY: replacing opcode 0x71 at 0x0010
04-16 17:05:39.730: W/dalvikvm(2118): threadid=11: thread exiting with uncaught exception (group=0x418c6700)
04-16 17:05:39.740: E/AndroidRuntime(2118): FATAL EXCEPTION: Thread-183
04-16 17:05:39.740: E/AndroidRuntime(2118): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.d2lvalence.idkeyauth.implementation.D2LSigner.getBase64HashString(D2LSigner.java:40)
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.d2lvalence.idkeyauth.implementation.D2LUserContext.buildAuthenticatedUriQueryString(D2LUserContext.java:129)
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.d2lvalence.idkeyauth.implementation.D2LUserContext.getQueryString(D2LUserContext.java:163)
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.d2lvalence.idkeyauth.implementation.D2LUserContext.createAuthenticatedUri(D2LUserContext.java:93)
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.example.d2lprofileupdate.D2LRest.GetName(D2LRest.java:100)
04-16 17:05:39.740: E/AndroidRuntime(2118): at com.example.d2lprofileupdate.MainActivity$1.run(MainActivity.java:32)
04-16 17:05:39.740: E/AndroidRuntime(2118): at java.lang.Thread.run(Thread.java:841)
04-16 17:05:39.820: D/libEGL(2118): loaded /system/lib/egl/libEGL_tegra.so
04-16 17:05:39.840: D/libEGL(2118): loaded /system/lib/egl/libGLESv1_CM_tegra.so
04-16 17:05:39.870: D/libEGL(2118): loaded /system/lib/egl/libGLESv2_tegra.so
04-16 17:05:39.900: D/OpenGLRenderer(2118): Enabling debug mode 0

SDK - R18 still has some bug

Some jar libraries in the libs/ folder are not picked up in some cases.
Just like arcgis for Android sample project "HelloWord", compiled without problems, but can't run properly.
04-16 14:56:33.104: D/dalvikvm(9369): Late-enabling CheckJNI
04-16 14:56:33.134: I/dalvikvm(9369): Turning on JNI app bug workarounds for target SDK version 7...
04-16 14:56:33.234: D/ArcGIS.LifeCycle(9369): map.onChildViewAdded
04-16 14:56:33.244: D/ArcGIS.LifeCycle(9369): map.initLayer
04-16 14:56:33.244: D/ArcGIS.LifeCycle(9369): >>>layer init startcom.esri.android.map.ags.ArcGISTiledMapServiceLayer
04-16 14:56:33.244: D/ArcGIS.LifeCycle(9369): layer init...
04-16 14:56:33.244: W/dalvikvm(9369): VFY: unable to find class referenced in signature (Lorg/codehaus/jackson/JsonNode;)
04-16 14:56:33.244: I/dalvikvm(9369): Could not find method org.codehaus.jackson.JsonNode.get, referenced from method com.esri.android.a.e.a
04-16 14:56:33.244: W/dalvikvm(9369): VFY: unable to resolve virtual method 4781: Lorg/codehaus/jackson/JsonNode;.get (Ljava/lang/String;)Lorg/codehaus/jackson/JsonNode;
04-16 14:56:33.244: D/dalvikvm(9369): VFY: replacing opcode 0x6e at 0x0005
04-16 14:56:33.244: I/dalvikvm(9369): Could not find method
org.codehaus.jackson.JsonNode.getTextValue, referenced from method com.esri.android.a.e.a
04-16 14:56:33.244: W/dalvikvm(9369): VFY: unable to resolve virtual method 4784: Lorg/codehaus/jackson/JsonNode;.getTextValue ()Ljava/lang/String;
04-16 14:56:33.244: D/dalvikvm(9369): VFY: replacing opcode 0x6e at 0x000b
04-16 14:56:33.244: E/HtcAppUsageStatsListener(9369): afterPerformResume
04-16 14:56:33.244: E/HtcAppUsageStatsListener(9369): java.lang.NullPointerException
04-16 14:56:33.244: E/HtcAppUsageStatsListener(9369): at android.app.HtcAppUsageStatsListener.afterPerformResume(HtcAppUsageStatsListener.java:77)
04-16 14:56:33.244: D/ArcGIS.TileCache(9369): max number of cached tiles:1000
04-16 14:56:33.244: D/ArcGIS.LifeCycle(9369): sdcache inited.
04-16 14:56:33.244: D/ArcGIS.TileCache(9369): SDCardCache
04-16 14:56:33.244: E/dalvikvm(9369): Could not find class
'org.codehaus.jackson.JsonFactory', referenced from method com.esri.core.internal.b.a.e.<clinit>
04-16 14:56:33.244: W/dalvikvm(9369): VFY: unable to resolve new-instance 717
(Lorg/codehaus/jackson/JsonFactory;) in Lcom/esri/core/internal/b/a/e;
04-16 14:56:33.244: D/dalvikvm(9369): VFY: replacing opcode 0x22 at 0x0000
04-16 14:56:33.244: W/dalvikvm(9369): VFY: unable to find class referenced in signature (Lorg/codehaus/jackson/JsonFactory;)
04-16 14:56:33.254: I/dalvikvm(9369): Could not find method org.codehaus.jackson.JsonFactory.createJsonParser, referenced from method com.esri.core.internal.b.a.e.a
04-16 14:56:33.254: W/dalvikvm(9369): VFY: unable to resolve virtual method 4760: Lorg/codehaus/jackson/JsonFactory;.createJsonParser
(Ljava/io/InputStream;)Lorg/codehaus/jackson/JsonParser;
04-16 14:56:33.254: D/dalvikvm(9369): VFY: replacing opcode 0x6e at 0x016c
04-16 14:56:33.254: I/dalvikvm(9369): Could not find method org.codehaus.jackson.JsonFactory.createJsonParser, referenced from method com.esri.core.internal.b.a.e.a
04-16 14:56:33.254: W/dalvikvm(9369): VFY: unable to resolve virtual method 4761: Lorg/codehaus/jackson/JsonFactory;.createJsonParser (Ljava/lang/String;)Lorg/codehaus/jackson/JsonParser;
04-16 14:56:33.254: D/dalvikvm(9369): VFY: replacing opcode 0x6e at 0x0022
04-16 14:56:33.254: I/dalvikvm(9369): Could not find method org.codehaus.jackson.JsonFactory.createJsonParser, referenced from method com.esri.core.internal.b.a.e.a
04-16 14:56:33.254: W/dalvikvm(9369): VFY: unable to resolve virtual method 4761:
Lorg/codehaus/jackson/JsonFactory;.createJsonParser (Ljava/lang/String;)Lorg/codehaus/jackson/JsonParser;
04-16 14:56:33.254: D/dalvikvm(9369): VFY: replacing opcode 0x6e at 0x001f
04-16 14:56:33.254: D/dalvikvm(9369): DexOpt: unable to opt direct call 0x1296 at 0x02 in Lcom/esri/core/internal/b/a/e;.<clinit>
04-16 14:56:33.264: W/dalvikvm(9369): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/esri/core/internal/b/a/e;
04-16 14:56:33.274: D/ArcGIS(9369): Failed to initialize the MapView.
04-16 14:56:33.274: D/ArcGIS(9369): java.lang.ExceptionInInitializerError
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.core.internal.a.a.k.a(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.android.map.ags.ArcGISTiledMapServiceLayer.initModel(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.android.map.ags.ArcGISTiledMapServiceLayer.initModel(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.android.map.LayerView.initLayer(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.android.map.MapView$1.a(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.android.map.MapView$1.call(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-16 14:56:33.274: D/ArcGIS(9369): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-16 14:56:33.274: D/ArcGIS(9369): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-16 14:56:33.274: D/ArcGIS(9369): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-16 14:56:33.274: D/ArcGIS(9369): at java.lang.Thread.run(Thread.java:864)
04-16 14:56:33.274: D/ArcGIS(9369): Caused by: java.lang.NoClassDefFoundError: org.codehaus.jackson.JsonFactory
04-16 14:56:33.274: D/ArcGIS(9369): at com.esri.core.internal.b.a.e.<clinit>(Unknown Source)
04-16 14:56:33.274: D/ArcGIS(9369): ... 11 more
04-16 14:56:33.274: D/ArcGIS.LifeCycle(9369): sdcard inited.
04-16 14:56:33.294: D/ArcGIS.LifeCycle(9369): map.onSizechanged
04-16 14:56:33.294: D/ArcGIS.LifeCycle(9369): !!! onSizeChangedSignal
04-16 14:56:33.294: D/ArcGIS.LifeCycle(9369): map.onLayout
04-16 14:56:33.304: D/ArcGIS.LifeCycle(9369): map.onLayout
04-16 14:56:33.314: D/memalloc(9369): /dev/pmem: Mapped buffer base:0x51fbc000 size:27017216 offset:24928256 fd:56
we might have encountered the same error - In my case the solution was to separate the Ant targets to two calls (i.e. "ant myParameters myTarget1 myTarget2", and "ant myParameters debug delivery"). Hope this works for you, anyhow - Google need to add better support for their undocumented/faulty changes (and stackoverflow isn't the best place for questions that are not originated in stupidity, as the lifetime of a complex question isn't too long here).
If that doesn't work for you please elaborate your question.

Memory Error during frame animation in Android application

Hi im trying to set up a frame animation with a series of images as a background for my splash page in an android application at the moment there is no errors but when I run the application it quits unexpectedly. The first error which follows 10 garbage collections is E/dalvikvm-heap(276): 1234272-byte external allocation too large for this process. I have 17 images I am using for the frame animation each of them are 50k or less so I dont think that the image sizes can be the issue.
The java code I have implemented in my main activity is as follows:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView frameanimation = (ImageView) findViewById(R.id.frame_animation);
AnimationDrawable frame_animation = (AnimationDrawable) frameanimation.getBackground();
frame_animation.setVisible(true, true);
frame_animation.start();
}
I then have this code implementing an image view within my XML Layout file:
<ImageView
android:id="#+id/frame_animation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/frame_animation"
android:background="#drawable/frame_animation"/>
and finally I have my animation drawable saved as 'frame_animation.xml' within my drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="#drawable/homebckgrnda1" android:duration="200" />
<item android:drawable="#drawable/homebckgrnda2" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda3" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda4" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda5" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda6" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda7" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda8" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda9" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda10" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda11" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda12" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda13" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda14" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda15" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda16" android:duration="50" />
<item android:drawable="#drawable/homebckgrnda17" android:duration="50" />
</animation-list>
The full LogCat log that I get when running the application is shown here:
04-16 13:51:33.703: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 906 objects / 64688 bytes in 69ms
04-16 13:51:33.983: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 208 objects / 9952 bytes in 66ms
04-16 13:51:34.203: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 54 objects / 2112 bytes in 51ms
04-16 13:51:34.443: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 13 objects / 536 bytes in 52ms
04-16 13:51:34.683: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 13 objects / 512 bytes in 54ms
04-16 13:51:35.133: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 20 objects / 824 bytes in 52ms
04-16 13:51:35.593: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 26 objects / 1216 bytes in 70ms
04-16 13:51:36.023: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 24 objects / 1008 bytes in 51ms
04-16 13:51:36.394: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 26 objects / 1128 bytes in 55ms
04-16 13:51:36.803: D/dalvikvm(276): GC_EXTERNAL_ALLOC freed 24 objects / 984 bytes in 50ms
04-16 13:51:37.143: E/dalvikvm-heap(276): 1234272-byte external allocation too large for this process.
04-16 13:51:37.143: E/GraphicsJNI(276): VM won't let us allocate 1234272 bytes
04-16 13:51:37.153: D/AndroidRuntime(276): Shutting down VM
04-16 13:51:37.153: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-16 13:51:37.203: E/AndroidRuntime(276): FATAL EXCEPTION: main
04-16 13:51:37.203: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.BadmintonTrain/com.android.BadmintonTrain.BadmintonTrainActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class android.widget.ImageView
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-16 13:51:37.203: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:51:37.203: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 13:51:37.203: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-16 13:51:37.203: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-16 13:51:37.203: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
04-16 13:51:37.203: E/AndroidRuntime(276): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.widget.ImageView
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-16 13:51:37.203: E/AndroidRuntime(276): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-16 13:51:37.203: E/AndroidRuntime(276): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.Activity.setContentView(Activity.java:1647)
04-16 13:51:37.203: E/AndroidRuntime(276): at com.android.BadmintonTrain.BadmintonTrainActivity.onCreate(BadmintonTrainActivity.java:21)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-16 13:51:37.203: E/AndroidRuntime(276): ... 11 more
04-16 13:51:37.203: E/AndroidRuntime(276): Caused by: java.lang.reflect.InvocationTargetException
04-16 13:51:37.203: E/AndroidRuntime(276): at android.widget.ImageView.<init>(ImageView.java:108)
04-16 13:51:37.203: E/AndroidRuntime(276): at java.lang.reflect.Constructor.constructNative(Native Method)
04-16 13:51:37.203: E/AndroidRuntime(276): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-16 13:51:37.203: E/AndroidRuntime(276): ... 22 more
04-16 13:51:37.203: E/AndroidRuntime(276): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.Bitmap.nativeCreate(Native Method)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.content.res.Resources.loadDrawable(Resources.java:1709)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.content.res.Resources.getDrawable(Resources.java:581)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:265)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.content.res.Resources.loadDrawable(Resources.java:1694)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.view.View.<init>(View.java:1885)
04-16 13:51:37.203: E/AndroidRuntime(276): at android.widget.ImageView.<init>(ImageView.java:112)
Any help is much appreciated, I just cannot figure out what is causing the problem.
Thanks
The images you are using might be too large for an animation. How large are they? In an animation, Android loads all of the images into memory and uncompresses them meaning that every pixel will take 4 bytes. So 50k would mean that your image is 111px x 111px. It seems from the error each frame is about 480 x 640, which is really large. Try using smaller images.

Classcastexception occurs randomly

I've an application in the market and many users have reported that the app is crashing a lot randomly. I'm trying to fix this but cannot fully understand the logs. Here's a extract from the log,
04-16 13:16:32.407 E/AndroidRuntime( 9237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.tabview.Tabs3}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.featured.FeaturedView}: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.os.Looper.loop(Looper.java:123)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at dalvik.system.NativeStart.main(Native Method)
04-16 13:16:32.407 E/AndroidRuntime( 9237): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maya.mobile.chiki/com.maya.mobile.chiki.featured.FeaturedView}: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.CustomTabHost.setCurrentTab(CustomTabHost.java:43)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.TabHost.addTab(TabHost.java:213)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.Tabs3.doCreateTabs(Tabs3.java:180)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.maya.mobile.chiki.tabview.Tabs3.onCreate(Tabs3.java:149)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-16 13:16:32.407 E/AndroidRuntime( 9237): ... 11 more
04-16 13:16:32.407 E/AndroidRuntime( 9237): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.AbsSpinner.onRestoreInstanceState(AbsSpinner.java:440)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.View.dispatchRestoreInstanceState(View.java:5940)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1140)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:767)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1127)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.view.View.restoreHierarchyState(View.java:5919)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1454)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Activity.onRestoreInstanceState(Activity.java:835)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Activity.performRestoreInstanceState(Activity.java:807)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
04-16 13:16:32.407 E/AndroidRuntime( 9237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473)
04-16 13:16:32.407 E/AndroidRuntime( 9237): ... 22 more
I got this log from one of my users.
Any help on this would be very very helpful.
Regards,
Hari
I was finally able to replicate this issue through an emulator set up with 50MB memory and running on GSM network speed. The issue seems to be because of history being cleared and so the data being lost which the app was already having. Not sure how I can handle this though.. any help???
My guess is that:
You have an activity containing a TabHost (fine)
The contents of those tabs are activities (bad)
You are duplicating android:id values among some of the widgets in those activities (fatal)
I had this issue as well. I had two activities with widgets bearing the same IDs. In one file, this widget was a Button and in another file the widget was a Spinner. I changed the IDs so that the Spinner had a different ID than the Button and the problem went away. It seems that Android runs in to problems if you use the same ID on two different classes of widgets.
I had a similar problem
It was a result of two views [Button] having the same ID
it happend to me because
the eclipse xml editor showed one button but registered 2 of the same ID
I solved it by cutting the button saving and then pasting it and saving again.
see: http://code.google.com/p/android/issues/detail?id=3981
Sometimes this happens to me.
First Try This:
Delete the R.java file so that it regenerates.
Then try this:
I rename the id of the widget in the XML, and in the java.
Then delete the R.java file so it regenerates.
Run it to flush it out. Rename it back to the way it was, and its good to go.

Categories

Resources