1

this is my problem, my app starts perfectly and the Activities works fine when call them, but when I go back to the main activity and start another one, my app crashes.

this is the error in the logcat:

06-29 23:48:46.885: E/AndroidRuntime(860): FATAL EXCEPTION: main
06-29 23:48:46.885: E/AndroidRuntime(860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whaoapps.maths/com.whaoapps.maths.Integrales}: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.os.Looper.loop(Looper.java:137)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread.main(ActivityThread.java:5041)
06-29 23:48:46.885: E/AndroidRuntime(860):  at java.lang.reflect.Method.invokeNative(Native Method)
06-29 23:48:46.885: E/AndroidRuntime(860):  at java.lang.reflect.Method.invoke(Method.java:511)
06-29 23:48:46.885: E/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-29 23:48:46.885: E/AndroidRuntime(860):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-29 23:48:46.885: E/AndroidRuntime(860):  at dalvik.system.NativeStart.main(Native Method)
06-29 23:48:46.885: E/AndroidRuntime(860): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-29 23:48:46.885: E/AndroidRuntime(860):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-29 23:48:46.885: E/AndroidRuntime(860):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.Activity.setContentView(Activity.java:1881)
06-29 23:48:46.885: E/AndroidRuntime(860):  at com.whaoapps.maths.Integrales.onCreate(Integrales.java:14)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.Activity.performCreate(Activity.java:5104)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-29 23:48:46.885: E/AndroidRuntime(860):  ... 11 more
06-29 23:48:46.885: E/AndroidRuntime(860): Caused by: java.lang.reflect.InvocationTargetException
06-29 23:48:46.885: E/AndroidRuntime(860):  at java.lang.reflect.Constructor.constructNative(Native Method)
06-29 23:48:46.885: E/AndroidRuntime(860):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-29 23:48:46.885: E/AndroidRuntime(860):  ... 25 more
06-29 23:48:46.885: E/AndroidRuntime(860): Caused by: java.lang.OutOfMemoryError
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.View.<init>(View.java:3330)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.View.<init>(View.java:3259)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.view.ViewGroup.<init>(ViewGroup.java:425)
06-29 23:48:46.885: E/AndroidRuntime(860):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:210)
06-29 23:48:46.885: E/AndroidRuntime(860):  ... 28 more

this is the xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/maths"
android:background="@android:color/white" />

<Button
android:id="@+id/button2"
android:layout_width="205dp"
android:layout_height="50dp"
android:layout_alignLeft="@+id/button1"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:onClick="derivadas" />

<Button
android:id="@+id/button1"
android:layout_width="205dp"
android:layout_height="50dp"
android:layout_above="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="58dp"
android:background="@android:color/transparent"
android:onClick="integrales" />

<com.google.ads.AdView android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="my_unit_id"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>

</RelativeLayout>

the android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.whaoapps.maths"
android:versionCode="1"
android:versionName="1.0" >



<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/maths_icono"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.google.ads.AdActivity"
           android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s mallestScreenSize" />
    <activity
        android:name="com.whaoapps.maths.MainActivity"
        android:screenOrientation="portrait"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity 
        android:name="com.whaoapps.maths.Derivadas"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
    <activity 
        android:name="com.whaoapps.maths.Integrales"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
</application>

</manifest>

1 Answer 1

0

Your app exceeded its memory budget while inflating the layout, as indicated in the stack trace:

06-29 23:48:46.885: E/AndroidRuntime(860): Caused by: java.lang.OutOfMemoryError

In particular, it happened while loading a bitmap into memory. The following line suggests that the the memory limit was hit on line #16 of the layout.

06-29 23:48:46.885: E/AndroidRuntime(860): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>

Most likely (I did not count), this will point to the image that is set to the ImageView:

android:src="@drawable/maths"

Any chance that maths drawable is a rather large (as in pixel dimensions) image? You'll probably want to scale it down and supply different versions for the various density buckets. Also, note that if you were testing on an emulator, you may want to bump up the heap size setting a bit. That may prevent the app from crashing, but obviously it does not address the underlying problem of your app using (too) much memory. Finally, have a look at the Loading Large Bitmaps Efficiently guide on de Android Developers website

2
  • man i don't understand what you are trying to tell me, i'm a beginner in this :( @MH.
    – Whady
    Jun 30, 2013 at 2:52
  • @Whady: Ok, so the short version is that your app is using too much memory. This is potentially caused by loading a (very) large image; one that is not suitable for the device you are testing your app on, or one that is simply larger than it needs to be for displaying. High-res images do not provide any visible benefit when they need to be down scaled, so make sure your images match their specific purpose. Anyways, beginner or not, definitely have a read through the linked guide. That should explain things much better than I can in a comment like this.
    – MH.
    Jun 30, 2013 at 3:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.