布局导致应用程序崩溃

时间:2014-05-09 11:41:02

标签: android out-of-memory inflate-exception

我遇到了一个问题,导致我的应用程序崩溃了 我相信我的问题来自

 setContentView(R.layout.activity_project_main);

在活动中, 但我无法解决它。也许在某处滥用上下文?

这是日志文件

05-09 11:16:55.420: E/AndroidRuntime(1506): FATAL EXCEPTION: main
05-09 11:16:55.420: E/AndroidRuntime(1506): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.project/com.company.project.ProjectMainActivity}: android.view.InflateException: Binary XML file line #155: Error inflating class <unknown>
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.os.Looper.loop(Looper.java:130)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at java.lang.reflect.Method.invokeNative(Native Method)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at java.lang.reflect.Method.invoke(Method.java:507)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at dalvik.system.NativeStart.main(Native Method)
05-09 11:16:55.420: E/AndroidRuntime(1506): Caused by: android.view.InflateException: Binary XML file line #155: Error inflating class <unknown>
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.Activity.setContentView(Activity.java:1657)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at com.company.project.ProjectMainActivity.onCreate(ProjectMainActivity.java:54)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-09 11:16:55.420: E/AndroidRuntime(1506):     ... 11 more
05-09 11:16:55.420: E/AndroidRuntime(1506): Caused by: java.lang.reflect.InvocationTargetException
05-09 11:16:55.420: E/AndroidRuntime(1506):     at java.lang.reflect.Constructor.constructNative(Native Method)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
05-09 11:16:55.420: E/AndroidRuntime(1506):     ... 24 more
05-09 11:16:55.420: E/AndroidRuntime(1506): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at aandroid.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.content.res.Resources.getDrawable(Resources.java:581)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.widget.ImageView.<init>(ImageView.java:118)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at android.widget.ImageView.<init>(ImageView.java:108)
05-09 11:16:55.420: E/AndroidRuntime(1506):     at com.company.project.widget.AspectRatioImageView.<init>(AspectRatioImageView.java:17)
05-09 11:16:55.420: E/AndroidRuntime(1506):     ... 27 more

这里是activity_project_main

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     tools:context="com.company.project.ProjectMainActivity"
   tools:ignore="MergeRootFrame" >

 <!-- 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc). -->
     <RelativeLayout
        android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#000" >

    <com.company.project.widget.AspectRatioImageView 
        android:id="@+id/headerImgBackground" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:scaleType="centerCrop" 
        android:src="@drawable/mainmenu_background_projectbuilding_image_3" />

    <FrameLayout
        android:id="@+id/FLProjectMainLines"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_above="@+id/LL">

        <ImageView
            android:id="@+id/arivProjectMainHeaderLineLeft"
            android:layout_width="278dp"
            android:layout_height="20dp"
            android:layout_gravity="left"
            android:layout_marginTop="100dp"
            android:background="@drawable/blue_background" />

        <ImageView
            android:id="@+id/arivProjectMainHeaderLineRight"
            android:layout_width="278dp"
            android:layout_height="20dp"
            android:layout_gravity="right"
            android:layout_marginTop="100dp"
            android:background="@drawable/blue_background" />

        <LinearLayout
            android:id="@+id/LLR1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:background="@android:color/transparent"
            android:orientation="horizontal" >

            <com.company.project.widget.AspectRatioImageView
                android:id="@+id/btnActivityProjectMainNews"
                android:layout_gravity="bottom"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:src="@drawable/selector_mainmenu_news" />

            <com.company.project.widget.AspectRatioImageView
                android:id="@+id/btnActivityProjectMainProject"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="bottom"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:src="@drawable/selector_mainmenu_project" />

            <com.company.project.widget.AspectRatioImageView
                android:id="@+id/btnActivityProjectMainEventsAndTraining"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:src="@drawable/selector_mainmenu_activity"
                android:text="Button" />
        </LinearLayout>
    </FrameLayout>

    <LinearLayout
        android:id="@+id/LL"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       android:layout_above="@+id/arivProjectMainHeaderLineFooter"
        android:orientation="vertical" 

        android:weightSum="3">

        <LinearLayout
            android:id="@+id/LLR2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
              android:layout_weight="1" >

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_services"
                android:id="@+id/btnActivityProjectMainServices"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_weight="1"
                android:adjustViewBounds="true" />

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_announcement"
                android:id="@+id/btnActivityProjectMainAnnouncement"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_weight="1" 
                android:adjustViewBounds="true"/>

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_companies"
                android:id="@+id/btnActivityProjectMainCompanies"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_weight="0.999999"
                android:adjustViewBounds="true" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/LLR3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
              android:layout_weight="1">

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_publish"
                android:id="@+id/btnActivityProjectMainPublish"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" 
                android:layout_weight="1"
                android:adjustViewBounds="true" />

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_fairs"
                android:id="@+id/btnActivityProjectMainFairs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"
                android:layout_weight="1" 
                android:adjustViewBounds="true" />

            <com.company.project.widget.AspectRatioImageView 
                 android:src="@drawable/selector_mainmenu_tenders"
                android:id="@+id/btnActivityProjectMainTenders"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_vertical"
                android:text="Button" 
                android:layout_weight="0.999999"
                android:adjustViewBounds="true" />

        </LinearLayout>

    </LinearLayout>

    <ImageView
              android:layout_above="@+id/vpProjectMainPager"
                android:background="@drawable/blue_background"
                android:id="@+id/arivProjectMainHeaderLineFooter"
                android:layout_width="match_parent"
                android:layout_height="10dp"/>

     <android.support.v4.view.ViewPager
    android:id="@+id/vpProjectMainPager"
      android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
          />

    </RelativeLayout>

  </FrameLayout>

1 个答案:

答案 0 :(得分:0)

在您的错误日志中,找到此行

05-09 11:16:55.420: E/AndroidRuntime(1506): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

问题是图像尺寸相当大。 尝试使用jpg或png而不是位图