I'm doing a simple animated application in Android in which I'm using multiple images to create a layout. The initial part of the application is working fine but after calling some activities I get this error:
06-05 09:14:06.752: E/AndroidRuntime(884): FATAL EXCEPTION: main
06-05 09:14:06.752: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.WhoWeAreActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.os.Handler.dispatchMessage(Handler.java:99)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.os.Looper.loop(Looper.java:137)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-05 09:14:06.752: E/AndroidRuntime(884): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884): at java.lang.reflect.Method.invoke(Method.java:511)
06-05 09:14:06.752: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-05 09:14:06.752: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-05 09:14:06.752: E/AndroidRuntime(884): at dalvik.system.NativeStart.main(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-05 09:14:06.752: E/AndroidRuntime(884): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-05 09:14:06.752: E/AndroidRuntime(884): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.Activity.setContentView(Activity.java:1881)
06-05 09:14:06.752: E/AndroidRuntime(884): at com.example.test.WhoWeAreActivity.onCreate(WhoWeAreActivity.java:13)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.Activity.performCreate(Activity.java:5104)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-05 09:14:06.752: E/AndroidRuntime(884): ... 11 more
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: java.lang.reflect.InvocationTargetException
06-05 09:14:06.752: E/AndroidRuntime(884): at java.lang.reflect.Constructor.constructNative(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-05 09:14:06.752: E/AndroidRuntime(884): ... 24 more
06-05 09:14:06.752: E/AndroidRuntime(884): Caused by: java.lang.OutOfMemoryError
06-05 09:14:06.752: E/AndroidRuntime(884): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.widget.ImageView.<init>(ImageView.java:120)
06-05 09:14:06.752: E/AndroidRuntime(884): at android.widget.ImageView.<init>(ImageView.java:110)
06-05 09:14:06.752: E/AndroidRuntime(884): ... 27 more
The layout file is the following (in an xml file called is who_we_are.xml):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<VideoView
android:id="@+id/VideoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView
android:id="@+id/whoweare"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/who_we_are" />
<ImageView
android:id="@+id/logo"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:src="@drawable/sunshinelogo" />
<ImageView
android:id="@+id/thought2"
android:layout_width="250dp"
android:layout_height="150dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="70dp"
android:src="@drawable/thought2" />
<RelativeLayout
android:id="@+id/thumbmenu"
android:layout_width="173dp"
android:layout_height="match_parent"
android:layout_marginTop="250dp"
android:gravity="left" >
<ImageView
android:id="@+id/tab1"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:src="@drawable/subtab1" />
<ImageView
android:id="@+id/tab2"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_below="@id/tab1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:src="@drawable/subtab2" />
<ImageView
android:id="@+id/tab3"
android:layout_width="120dp"
android:layout_height="20dp"
android:layout_below="@id/tab2"
android:layout_marginBottom="10dp"
android:layout_marginLeft="27dp"
android:src="@drawable/subtab3" />
<ImageView
android:id="@+id/tab4"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_below="@id/tab3"
android:layout_marginBottom="10dp"
android:layout_marginLeft="27dp"
android:src="@drawable/subtab4" />
<ImageView
android:id="@+id/tab5"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_below="@id/tab4"
android:layout_marginBottom="10dp"
android:layout_marginLeft="25dp"
android:src="@drawable/subtab5" />
<ImageView
android:id="@+id/tab6"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_below="@id/tab5"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:src="@drawable/subtab6" />
</RelativeLayout>
<LinearLayout
android:id="@+id/introbg"
android:layout_width="318dp"
android:layout_height="381dp"
android:layout_gravity="right"
android:layout_marginRight="25dp"
android:layout_marginTop="25dp"
android:background="#300000ff"
android:orientation="vertical" >
<TextView
android:id="@+id/introduction "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingTop="25dp"
android:text="Wo We Are"
android:textColor="#D8F83F"
android:textSize="30sp" />
<TextView
android:id="@+id/hr "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" _________________________________ "
android:textColor="#D8F83F"
android:textSize="20sp" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/hr "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D8F83F"
android:textSize="20sp" />
</ScrollView>
</LinearLayout>
<ImageView
android:id="@+id/belowbar"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="@drawable/belowbar" />
</FrameLayout>
I set this layout in my java file and this is the code for it (the file name is WhoWeAreActivity.java
):
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
public class WhoWeAreActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.who_we_are);
}
}
I'm calling WhoWeAreActivity.java
on the click event of another java file named CorporateProfileActivity.java
like this:
animation = AnimationUtils.loadAnimation(this, R.anim.intro_scale);
ivcp2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ivcp2.startAnimation(animation);
openWhoWeAre(view);
}
});
public void openWhoWeAre(View view) {
// Do something in response to button
Intent intent = new Intent(this, WhoWeAreActivity.class);
startActivity(intent);
}
Here ivcp2
is an imageview variable. I don't have any idea why I'm getting this error. I'm new to android development. Any kind of help is highly appreciated. I've been searching for a solution for the past 2 days but didn't make any progress.
your StackTrace is pointing out the following
java.lang.OutOfMemoryError
your device is unable to allocate enough memory for the bitmap you want to show inside WhoWeAreActivity
You're loading too large images ... You can reduce their size either manually, if loading from resources, or dynamically. Here is a series of articles that should help you on this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.