Using Images of high resolution gives an BITMAP error? - android

I have created an application which consists of only ImageViews.
Also According to the app requirement I had to use Hi Quality Images with 1024*780 Resolution through 200*250 resolution Images. All Images sums up to almost 45 images!!!.
In High-End (Heap memory >=32)Devices, I found it is running Smoothly, Coming to the low end (Heap memory <32) devices & also on MICROMAX A 65, I received Some Crashing Reports & I gave a try on a 16mb heap memory Emulator.
After Clicking first Image it is showing:
06-29 05:16:28.572: W/dalvikvm(846): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
06-29 05:16:28.665: E/AndroidRuntime(846): FATAL EXCEPTION: main
06-29 05:16:28.665: E/AndroidRuntime(846): java.lang.OutOfMemoryError
06-29 05:16:28.665: E/AndroidRuntime(846): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.content.res.Resources.getDrawable(Resources.java:660)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.widget.ImageView.resolveUri(ImageView.java:616)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.widget.ImageView.setImageResource(ImageView.java:349)
06-29 05:16:28.665: E/AndroidRuntime(846): at com.mshah.learnandplaybasiccolors.Learn.setImageWithSound(Learn.java:123)
06-29 05:16:28.665: E/AndroidRuntime(846): at com.mshah.learnandplaybasiccolors.Learn.onClick(Learn.java:88)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.view.View.performClick(View.java:4202)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.view.View$PerformClick.run(View.java:17340)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.os.Handler.handleCallback(Handler.java:725)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.os.Handler.dispatchMessage(Handler.java:92)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.os.Looper.loop(Looper.java:137)
06-29 05:16:28.665: E/AndroidRuntime(846): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-29 05:16:28.665: E/AndroidRuntime(846): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 05:16:28.665: E/AndroidRuntime(846): at java.lang.reflect.Method.invoke(Method.java:511)
06-29 05:16:28.665: E/AndroidRuntime(846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-29 05:16:28.665: E/AndroidRuntime(846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-29 05:16:28.665: E/AndroidRuntime(846): at dalvik.system.NativeStart.main(Native Method)
I am not using Bitmap, It is giving the bitmap error: How can I resolve this error ???
or
Should I exclude the support for such devices?

You shouldn't load all these images into memory at the same time. Why would you? You should create some gallery of thumbnails or something along those lines and lazy load as needed. There is no way around this. You're going to run out of memory loading images the way you're doing, even on the high end devices since android only gives you a very small memory footprint within which to operate.

Managing bitmap memory
this doc is helping a lot regarding bitmap issue.

Related

force close when change theme in android manifest

I have changed the theme for some activities, but when I want to run the AVD go to Force Stop.
This is my activity manifest:
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent."
android:label="#string/title_activity_login" >
<intent-filter>
and this is my xml activity:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.gpsportalsms.LoginActivity"
android:background="#drawable/background3"
tools:ignore="MergeRootFrame" >
</FrameLayout>
I add the LogCat in below:
06-29 16:10:24.015: W/dalvikvm(1420): threadid=1: thread exiting with uncaught exception (group=0xa4ceeb20)
06-29 16:10:24.015: E/AndroidRuntime(1420): FATAL EXCEPTION: main
06-29 16:10:24.015: E/AndroidRuntime(1420): Process: com.example.gpsportalsms, PID: 1420
06-29 16:10:24.015: E/AndroidRuntime(1420): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gpsportalsms/com.example.gpsportalsms.NotifySMSReceived}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.os.Handler.dispatchMessage(Handler.java:102)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.os.Looper.loop(Looper.java:136)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-29 16:10:24.015: E/AndroidRuntime(1420): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 16:10:24.015: E/AndroidRuntime(1420): at java.lang.reflect.Method.invoke(Method.java:515)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-29 16:10:24.015: E/AndroidRuntime(1420): at dalvik.system.NativeStart.main(Native Method)
06-29 16:10:24.015: E/AndroidRuntime(1420): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.example.gpsportalsms.NotifySMSReceived.onCreate(NotifySMSReceived.java:20)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.Activity.performCreate(Activity.java:5231)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-29 16:10:24.015: E/AndroidRuntime(1420): ... 11 more
What is wrong?
Remove the "." in Theme.Translucent.
Use this
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent"
android:label="#string/title_activity_login" >
A quick search lands me into this SO question : How to make an Android Translucent theme a little darker?
The mentioned question however isn't much related to yours, but provides some reference. Haven't tried though.
As it says the code must be like
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent"
android:label="#string/title_activity_login" >
Notice the '.' shouldn't be there.

java.lang.OutOfMemoryError: bitmap size exceeds VM budget + ViewPagerAdapter

Helllo,
I got this problem with ViewPagerAdapter. On various phones it sometimes crashes and sometimes not and can't put my finger on the cause. I even made largeHeap for API>14 and still got this on. Anyone know what's going on?
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:563)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:439)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1981)
at android.content.res.Resources.getDrawable(Resources.java:601)
at android.widget.ImageView.resolveUri(ImageView.java:501)
at android.widget.ImageView.setImageResource(ImageView.java:280)
at com.example.package.ViewPagerAdapter.instantiateItem(ViewPagerAdapter.java:85)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1048)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(NativeStart.java)

Exception with Android WebView

I have this exception:
java.lang.NullPointerException
at android.webkit.WebViewClassic.requestFocus(WebViewClassic.java:10003)
at android.webkit.WebView.requestFocus(WebView.java:2133)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2338)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2338)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2382)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2341)
at android.view.View.requestFocus(View.java:6538)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1899)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
But it doesn't tell me what line it happened on or anything else. Any idea how to debug this?
Thanks,
Alex

Why I can't open my camera?

I try to run this , but it force close happen like this
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): java.lang.RuntimeException: Fail to connect to camera service
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.native_setup(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.<init>(Camera.java:294)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.open(Camera.java:271)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.example.Preview.surfaceCreated(Preview.java:37)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.draw(ViewRoot.java:1527)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Looper.loop(Looper.java:123)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invoke(Method.java:507)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at dalvik.system.NativeStart.main(Native Method)
Sounds like your device does not have a camera (emulator!) or that you dont have the appropriate permissions defined in your manifest.
android.permission.CAMERA
I think the problem is in your device, because the tutorial has ask you to add the permission. Edit your AVD and add camera support in hardware

java.lang.OutOfMemoryError bitmap create?

I just got this stack trace from the marketplace error reporting and have no idea where to being to track the problem down, any help appreciated.
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:463)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.Resources.getDrawable(Resources.java:581)
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:440)
at com.android.internal.view.menu.IconMenuItemView.initialize(IconMenuItemView.java:109)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:594)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.IconMenuView.updateChildren(IconMenuView.java:351)
at com.android.internal.view.menu.IconMenuView.initialize(IconMenuView.java:333)
at com.android.internal.view.menu.MenuBuilder$MenuType.getMenuView(MenuBuilder.java:199)
at com.android.internal.view.menu.MenuBuilder.getMenuView(MenuBuilder.java:323)
at com.android.internal.policy.impl.PhoneWindow.initializePanelContent(PhoneWindow.java:858)
at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:435)
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:621)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1339)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1668)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.widget.TabHost.dispatchKeyEvent(TabHost.java:278)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I'm getting the same error on an application I've developed for Android 2.1 and Android 2.2 but run on Android 4.0.1 ICS. The same app would run on Android 2.1 but cause a crash with the above error on ICS. If you're drawing something relatively big to the size of the screen, consider checking from that place.

Categories

Resources