0

my android app is unable to start the Activity for some reason, the Activity's name is Caperucita, but I can't see what the problem is, theres another activity like this that runs perfecty, and is Ricitos. maybe you can help me

the error in the logcat:

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

the android manifest:

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.storyteller.MainActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        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="AcercaDe"
          android:screenOrientation="portrait"
          android:theme="@android:style/Theme.NoTitleBar"></activity>

    <activity android:name="Cuentos"
          android:screenOrientation="portrait"
          android:theme="@android:style/Theme.NoTitleBar"></activity>

    <activity android:name="Ricitos"
          android:screenOrientation="portrait"
          android:theme="@android:style/Theme.NoTitleBar"></activity>

    <activity android:name="Caperucita"
          android:screenOrientation="portrait"
          android:theme="@android:style/Theme.NoTitleBar"></activity>

</application>

</manifest>

the Xml file:

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

 <ScrollView

     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_marginTop="0dp" >

     <RelativeLayout

    android:id="@+id/rootRL"
    android:layout_width="match_parent"
    android:layout_height="262dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_weight="0.83"
    android:background="@drawable/caperucita_roja"
    android:orientation="vertical" >

         <RelativeLayout
             android:layout_width="800dp"
             android:layout_height="262dp"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true" >

             <ImageButton
                 android:id="@+id/ib3"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentLeft="true"
                 android:layout_alignParentTop="true"
                 android:background="@android:color/transparent"
                 android:onClick="contar"
                 android:src="@drawable/boton_contar_caperucita" />

             <ImageButton
                 android:id="@+id/ib2"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentTop="true"
                 android:layout_toRightOf="@+id/ib3"
                 android:background="@android:color/transparent"
                 android:onClick="play"
                 android:src="@drawable/boton_play_caperucita" />

             <ImageButton
                 android:id="@+id/imageButton3"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentTop="true"
                 android:layout_toRightOf="@+id/ib2"
                 android:background="@android:color/transparent"
                 android:onClick="pause"
                 android:src="@drawable/boton_pausa_caperucita" />

         </RelativeLayout>

</RelativeLayout>
</ScrollView>

</RelativeLayout>

java file:

package com.example.storyteller;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
import android.widget.ImageView;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;

public class Caperucita extends Cuentos {

MediaPlayer mp;
int  posicion=0;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.caperucita);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


}

public void destruir() {
    if(mp!=null) 
        mp.release();
}


public void contar(View view){
    destruir ();
    mp=MediaPlayer.create(this,R.raw.caperucitaroja);
    mp.start();

    }

public void pause(View view) {
    if(mp != null && mp.isPlaying()) {
        posicion = mp.getCurrentPosition();
        mp.pause();

    }        
}




public void play(View view) {

    if(mp != null && mp.isPlaying()==false) {
        mp.seekTo(posicion);
        mp.start();

    }   

}

protected void onResume() {
    if(mp != null && !mp.isPlaying())
        mp.start();
    super.onResume();
}

public void onPause() {

    super.onPause(); 
if (mp != null)
    mp.pause(); 
}


public void onBackPressed(){
    super.onBackPressed();
    System.exit(0);     
    }

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        exitByBackKey();

        //moveTaskToBack(false);

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

protected void exitByBackKey() {

    AlertDialog alertbox = new AlertDialog.Builder(this)
    .setMessage("¿De verdad desea salir? si lo hace no podrá reproducir el audio desde donde lo dejó")
    .setPositiveButton("Si", new DialogInterface.OnClickListener() {

        // do something when the button is clicked
        public void onClick(DialogInterface arg0, int arg1) {

            finish();
            //close();


        }
    })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {

        // do something when the button is clicked
        public void onClick(DialogInterface arg0, int arg1) {
                       }
    })
      .show();

}


}
4
  • Can you show us the layout file inflated in your activity? Commented Jul 12, 2013 at 2:14
  • I just post it! @RenatoLochetti Commented Jul 12, 2013 at 2:15
  • Can you post Caperucita.java? Commented Jul 12, 2013 at 2:27
  • there it is man! @E.Odebugg Commented Jul 12, 2013 at 2:32

2 Answers 2

1

Looks the file size of your background is too big. Try removing the background attribute in the relative layout below, and see if you get the crash.

 <RelativeLayout
    android:id="@+id/rootRL"
    android:layout_width="match_parent"
    android:layout_height="262dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_weight="0.83"
    android:background="@drawable/caperucita_roja"
    android:orientation="vertical" >

To fix the problem you need more memory or you need to use less of it. Getting more memory isn't really possible, but you can specify a larger heap size. In your manifest, use the largeHeap attribute:

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

You can read more about that attribute here.

To decrease the amount of memory needed, you need to decrease the size of that background image. I'd look at reducing the size of that image. If reducing the dimensions is not possible, look into optimizing the image with a program like PNGCrush, which can help reduce the file's size without affecting the quality of the image. Here's a link to how to use PNGCrush from the command line.

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

6 Comments

that's the problem but why it doesn't work in Caperucita.java while in Ricitos.java it works? @Flynn81
@Whady - How big are the background graphics files? The problem is that the system ran out of memory while loading this layout.
480x3969 in the Caperucita.java and 480x2461 in ricitos.java @TedHopp
Keep in mind, if your first activity is in the background while your second activity is in the foreground, the memory allocated for that first activity's drawable won't be garbage collected. So even though it loads once, loading the image a second time seems to be crashing your app.
@Whady I updated the answer with two suggestions. Definitely try the largeHeap attribute, I've had good luck with that before when confronted with out of memory exceptions.
|
0

You need to reduce the memory impact of your graphics files. From the stack trace, it's clear that the system ran out of memory while loading the caperucita_roja background. (That file, at 480x3969, is particularly large. Uncompressed in memory it will take up over 7MB. On many devices, that's a considerable fraction of the total memory available to an app.) Remember that Android devices are quite constrained in terms of available memory.

The training article Loading Large Bitmaps Efficiently provides strategies that can help with this.

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.