我在这个问题上经历过几个帖子,但没有任何帮助。问题仅出现在大屏幕设备上。下面是堆栈跟踪。
Logcat输出
03-13 15:21:18.863: E/AndroidRuntime(6334): FATAL EXCEPTION: main
03-13 15:21:18.863: E/AndroidRuntime(6334): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dzo.seattlesnightlife/com.dzo.seattlesnightlife.StoreDescription}: android.view.InflateException: Binary XML file line #29: Error inflating class <unknown>
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.os.Looper.loop(Looper.java:137)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-13 15:21:18.863: E/AndroidRuntime(6334): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 15:21:18.863: E/AndroidRuntime(6334): at java.lang.reflect.Method.invoke(Method.java:511)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-13 15:21:18.863: E/AndroidRuntime(6334): at dalvik.system.NativeStart.main(Native Method)
03-13 15:21:18.863: E/AndroidRuntime(6334): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class <unknown>
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:805)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.Activity.setContentView(Activity.java:1867)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.dzo.seattlesnightlife.StoreDescription.init(StoreDescription.java:195)
03-13 15:21:18.863: E/AndroidRuntime(6334): at com.dzo.seattlesnightlife.StoreDescription.onCreate(StoreDescription.java:188)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.Activity.performCreate(Activity.java:5008)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-13 15:21:18.863: E/AndroidRuntime(6334): ... 11 more
03-13 15:21:18.863: E/AndroidRuntime(6334): Caused by: java.lang.reflect.InvocationTargetException
03-13 15:21:18.863: E/AndroidRuntime(6334): at java.lang.reflect.Constructor.constructNative(Native Method)
03-13 15:21:18.863: E/AndroidRuntime(6334): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-13 15:21:18.863: E/AndroidRuntime(6334): ... 30 more
03-13 15:21:18.863: E/AndroidRuntime(6334): Caused by: java.lang.OutOfMemoryError
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.content.res.Resources.loadDrawable(Resources.java:1930)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.content.res.Resources.getDrawable(Resources.java:659)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.content.res.Resources.loadDrawable(Resources.java:1915)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.View.<init>(View.java:3336)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.view.ViewGroup.<init>(ViewGroup.java:427)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
03-13 15:21:18.863: E/AndroidRuntime(6334): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
03-13 15:21:18.863: E/AndroidRuntime(6334): ... 33 more
XML布局文件
<com.dzo.seattlesnightlife.ui.HeaderBar
android:id="@+id/baseHeaderBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/listViewSearch"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/baseHeaderBar"
android:layout_marginBottom="55dp"
android:listSelector="@drawable/list_sel"
android:cacheColorHint="#00000000"
android:divider="@color/divider_list"
android:layout_marginTop="-3dp"
android:dividerHeight="2dp" />
<TextView
android:id="@+id/txtNoData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/no_data"
android:textColor="@color/white"
android:textSize="18sp"
android:visibility="gone" />
<ScrollView
android:id="@+id/scrollLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/baseHeaderBar"
android:layout_marginBottom="60dp"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/linScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/linImgAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/linImgListingPhoto"
android:layout_width="143dp"
android:layout_height="143dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_description"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgListingPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/d_desc"
android:scaleType="fitXY" />
</LinearLayout>
<ImageButton
android:id="@+id/btnFav"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="top|left"
android:layout_marginTop="5dp"
android:background="@drawable/ic_fav"
android:contentDescription="@drawable/ic_fav" />
<LinearLayout
android:id="@+id/linPromoTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/linImgListingPhoto"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:gravity="top"
android:orientation="vertical" >
<TextView
android:id="@+id/txtListingTitle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/bg_description"
android:gravity="center_vertical|center_horizontal"
android:textColor="@color/white"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/linAddressWebsite"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="3dp"
android:background="@drawable/bg_description"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="32dp"
android:id="@+id/relStoreAddress"
android:background="@drawable/highlight_rnd_top" >
<ImageView
android:id="@+id/imgIcMap"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:contentDescription="@drawable/ic_map"
android:src="@drawable/ic_map" />
<TextView
android:id="@+id/txtStoreAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/imgIcMap"
android:layout_centerVertical="true"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:contentDescription="@drawable/arrow_white"
android:src="@drawable/arrow_white" />
</RelativeLayout>
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="0sp"
android:background="@color/line" />
<RelativeLayout
android:id="@+id/relStoreContact"
android:layout_width="match_parent"
android:layout_height="34dp"
android:background="@drawable/highlight_mid" >
<ImageView
android:id="@+id/imgIcCall"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@drawable/ic_call"
android:src="@drawable/ic_call" />
<TextView
android:id="@+id/txtStorePhone"
android:layout_toRightOf="@+id/imgIcCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:contentDescription="@drawable/arrow_white"
android:src="@drawable/arrow_white" />
</RelativeLayout>
<View
android:id="@+id/view3"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="0sp"
android:background="@color/line" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="32dp"
android:id="@+id/relStoreWeb"
android:background="@drawable/highlight_rnd_bottom" >
<ImageView
android:id="@+id/imgIcWeb"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:contentDescription="@drawable/ic_web"
android:src="@drawable/ic_web" />
<TextView
android:layout_toRightOf="@+id/imgIcWeb"
android:id="@+id/txtStoreWebsite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="18sp"
android:text="@string/visit_web"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:contentDescription="@drawable/arrow_white"
android:src="@drawable/arrow_white" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/linDescInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<include layout="@layout/part_store_sched_tick" />
<LinearLayout
android:id="@+id/linStoreDescTitle"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="center"
android:gravity="center|top"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:visibility="gone" >
<TextView
android:id="@+id/txtDescTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_description"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:singleLine="true"
android:text="@string/d_desc"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linStoreDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/bg_desc"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone" >
<com.dzo.seattlesnightlife.ui.ExpandablePanel
android:id="@+id/descPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
custom:animationDuration="25"
custom:collapsedHeight="80dp"
custom:content="@+id/txtDesc"
custom:handle="@+id/expand" >
<TextView
android:id="@id/txtDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"/>
<View
android:id="@+id/view4"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="0sp"
android:background="@color/line"/>
<RelativeLayout
android:id="@id/expand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/txt_highlight"
android:visibility="gone">
<TextView
android:id="@+id/txtShowMoreLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/show_more"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="@+id/imgMoreLess"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/txtShowMoreLess"
android:background="@drawable/arrow_down"
android:contentDescription="@drawable/arrow_down"
android:visibility="gone" />
</RelativeLayout>
</com.dzo.seattlesnightlife.ui.ExpandablePanel>
</LinearLayout>
<include layout="@layout/part_store_info" />
<LinearLayout
android:id="@+id/linShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="8dp"
android:gravity="top|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linStoreShareBox"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="top"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/txtStoreShareTittle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_description"
android:gravity="center|center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:singleLine="true"
android:text="@string/d_share"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
<include layout="@layout/share_lay_part" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<com.dzo.seattlesnightlife.ui.FooterBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/baseFooterBar"/>
</RelativeLayout>
每当我在大屏幕设备或模拟器上运行我的应用程序时,我都会遇到这个异常情况。通过堆栈,当我检查行号。在XML中,对于textView,它是android:layout_height
。这条线没有。应用程序崩溃的活动是setContentView()
。 OutOfMemoryError
指出我的drawables有问题。所以,我调整了我的绘图,但没有任何帮助我。无法找出崩溃的真正原因。
我的Java file。抱歉无法在这里发布,因为它超出了身体限制,我量身定做,因为它有大约5k行代码。
好的,当我将堆大小增加到48 MB应用程序没有崩溃,但是有16 MB堆时,它仍然崩溃。
答案 0 :(得分:12)
答案 1 :(得分:2)
您的XML错误只是主要错误的结果: OutOfMemoryError
只要您没有找到改善内存管理的线索,就会出现这类错误(XML或其他)
你的XML是正确的,没有错误,第29行是你的应用程序出现OutOfMemoryError时的“点”
答案 2 :(得分:0)
我还认为OutOfMemoryError
是logcat
报告的决定性部分。我将Android虚拟设备的VM堆从16MB增加到32 MB。现在它有效。
答案 3 :(得分:0)
我有一个类似的问题,它选择大的布局 - 大于屏幕,并将位图缩放到它。 那时记忆力不足了。 我使背景和按钮的尺寸变小了,它就出现了。 然后我看到了一个太大的屏幕布局。