0

I am getting this error:

E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.OutOfMemoryError
                  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
                  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
                  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
                  at android.content.res.Resources.loadDrawable(Resources.java:2988)
                  at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                  at android.view.View.<init>(View.java:3563)
                  at android.widget.ImageView.<init>(ImageView.java:125)
                  at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
                  at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
                  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1013)
                  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1072)
                  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
                  at mario.fragments.SplashScreenSalir_Fragment.onCreateView(SplashScreenSalir_Fragment.java:30)
                  at android.app.Fragment.performCreateView(Fragment.java:1699)
                  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
                  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
                  at android.app.BackStackRecord.run(BackStackRecord.java:682)
                  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1455)
                  at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
                  at android.os.Handler.handleCallback(Handler.java:730)
                  at android.os.Handler.dispatchMessage(Handler.java:92)
                  at android.os.Looper.loop(Looper.java:176)
                  at android.app.ActivityThread.main(ActivityThread.java:5419)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:525)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
                  at dalvik.system.NativeStart.main(Native Method)
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.Restarter.getActivities
W/dalvikvm: VFY: unable to resolve instanceof 2541 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/Restarter;
D/dalvikvm: VFY: replacing opcode 0x20 at 0x006f

12/10 01:19:15: Launching app
I/Process: Sending signal. PID: 28067 SIG: 9
Application terminated.

I have been reading about it, but I have just read about Virtual Machines, and I am getting it using my own phone.

It is kind of weird, because the code actually works. I mean, after crashing, if I push again the button, it works (I attach a couple of images)

enter image description here

enter image description here

The code of my Fragment is just a simple SplashScreen:

      package mario.fragments;


    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;
    import android.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;

    import mario.rankit.MainActivity;
    import mario.rankit.R;

        /**
         * A simple {@link Fragment} subclass.
         */
        public class SplashScreenSalir_Fragment extends Fragment {
            View view;

            pu

blic SplashScreenSalir_Fragment() {
            // Required empty public constructor
        }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_splash_screen_salir_, container, false);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(view.getContext(), MainActivity.class);
                startActivity(intent);
            }
        }, 3000);

        return view;
    }

}

Do you know how to solve it?

3

1 Answer 1

4

You are using very large images for the splash. You may need to reduce its size. You don't need such a high-resolution Bitmap. A 2048 by 2048 or 1024 by 1024 Bitmap occupies such a huge memory. Imagine having multiple such images?

There are actually two solutions:

  • Reduce the image size but maintain aspect ratio.
  • Use Glide Library

Using Glide, you can be able to reduce the Image size at run time.

For example:

Glide  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .override(600, 200)
    .fitCenter() 
    .into(imageViewResizeFitCenter);

See more at: - Glide Image Resizing and Scaling

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.