-2

Hi I have been trying to develop a simple game in Eclipse I'm at the stage of trying to add the background image however when I try to run the app I get the "unfortunately has stopped working" looking at the log cat my best guess is that something is wrong with the bitmap factory line below:

background = new Background(BitmapFactory.decodeResource(getResources(), R.drawable.underwater), ScreenWidth, this);

Here is the Log Cat I am recieving:

FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:376)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:406)
at com.example.deepseadiver.GamePanel.<init>(GamePanel.java:21)
at com.example.deepseadiver.Game.onCreate(Game.java:69)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
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:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)

Any help or suggestions for how to fix this are much appreciated.

Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68
randomer
  • 29
  • 4
  • 11
  • http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – nhaarman Apr 09 '15 at 12:32

1 Answers1

0

Update you manifest file,inside application tag set large heap -

 .
 .
 <application
    android:largeHeap="true"
    . .
  >

   ....
  </application>
Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68