0

My app crashes after adding splash screen. Below is the error log, xml and java file. I have mostly used the same code in other apps but i can't get why its not working here Please Help

04-09 20:36:05.469: E/AndroidRuntime(27529): FATAL EXCEPTION: main
04-09 20:36:05.469: E/AndroidRuntime(27529): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zaidi.mindmapmaker/com.behram.mindmapmaker.SplashScreen}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.os.Looper.loop(Looper.java:137)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.main(ActivityThread.java:4424)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at dalvik.system.NativeStart.main(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Activity.setContentView(Activity.java:1835)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at com.behram.mindmapmaker.SplashScreen.onCreate(SplashScreen.java:18)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Activity.performCreate(Activity.java:4465)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 11 more
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: java.lang.reflect.InvocationTargetException
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 24 more
04-09 20:36:05.469: E/AndroidRuntime(27529): Caused by: java.lang.OutOfMemoryError
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.content.res.Resources.loadDrawable(Resources.java:1935)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.widget.ImageView.<init>(ImageView.java:119)
04-09 20:36:05.469: E/AndroidRuntime(27529):    at android.widget.ImageView.<init>(ImageView.java:109)
04-09 20:36:05.469: E/AndroidRuntime(27529):    ... 27 more

splash_screen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/splash" />

</LinearLayout>

SplashScreen.java

public class SplashScreen extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, ActivityB.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

}

user3346237
  • 17
  • 1
  • 8

2 Answers2

0

Caused by: java.lang.OutOfMemoryError

You need to scale down your Image. Its occupying too much space leading to OOM. I think as of api 3.0 bitmap pixel data is stored on the heap.

Out of Memory error with Bitmap

Quoting docs

If your app has reached the heap capacity and tries to allocate more memory, it will receive an OutOfMemoryError.

Check loading images efficiently @

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Also check

Check this

https://developer.android.com/training/displaying-bitmaps/manage-memory.html

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

The error is caused by java.lang.OutOfMemoryError

It depends how big your bitmap is, Android seems to allocate a little more space than the size of the image when you read the size on your computer. So...

  • You could just use a smaller image.
  • Google have actually published a guide on avoiding OutOfMemoryErrors here which will help a lot, though I had to use a smaller image size as well.
  • One method that will almost definitely work is to set android:largeHeap="true" in your manifest, between your application tags. This will increase your heap size, but may make your app lag a little.

Maybe for you, a combination of these ideas will work.

See this Link for Displaying Bitmaps Efficiently

OR

Add image to image view programmatically

 if(imageView != null) {
    ((BitmapDrawable)imageView.getDrawable()).getBitmap().recycle();
    imageView = (ImageView) view.findViewById(R.id.imageView);
    imageView.setImageResource(resID);
}
else {
    imageView = (ImageView) view.findViewById(R.id.imageView);
    imageView.setImageResource(resID);
}
Lal
  • 14,726
  • 4
  • 45
  • 70
  • there is no need to call recycle as of 3.0 and above. read manage bitmaps on 3.0 and higher https://developer.android.com/training/displaying-bitmaps/manage-memory.html – Raghunandan Apr 09 '14 at 16:40
  • Should not recommend `android:largeHeap="true"`. http://developer.android.com/training/articles/memory.html. Quoting docs **Never request a large heap simply because you've run out of memory** and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. Larger the heap more frequent garbage collection – Raghunandan Apr 09 '14 at 16:47
  • that's why i posted a comment to let you know not to suggest `android:largeHeap="true"` coz there is only 1 imageview and that is really no needed – Raghunandan Apr 09 '14 at 16:53