运行此活动时,我收到以下随机异常。我在SO上找到另一个线程,建议我所有的样式都继承自parent =“android:Theme”,但这没有帮助。我已经运行了HierarchyViewer和layoutopt工具,但没有发现布局文件有任何问题。我已经清理了这个项目。
例外情况正在线上发生:
ReceiptActivity.java:54 setContentView(R.layout.receipt_activity);
这是布局文件,receipt_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<LinearLayout android:layout_width="fill_parent"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_marginTop="10dip"
android:textSize="19sp"
android:text="@string/receipt_question"
android:gravity="center"/>
<EditText
android:id="@+id/txtEmailOrSms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:textSize="15sp"
android:maxLines="1"
android:layout_gravity="left"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="textEmailAddress"
android:hint="@string/enter_email"
android:imeOptions="actionDone"
/>
<RadioGroup
android:id="@+id/receiptTypeRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/emailReceipt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Receipt"
android:textSize="15sp"
android:checked="true"
android:width="150dip"
android:layout_marginRight="5dip"
android:textColor="#FFF"
>
</RadioButton>
<RadioButton
android:id="@+id/smsReceipt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Receipt"
android:textSize="15sp"
android:width="150dip"
android:layout_marginRight="5dip"
android:textColor="#FFF"
>
</RadioButton>
</RadioGroup>
</LinearLayout>
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:background="@drawable/button_bar_background"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true"
style="@android:style/ButtonBar">
<Button
android:id="@+id/noThanksBtn"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_marginLeft="1dip"
style="@style/DarkButton"
android:text="@string/no_thanks"/>
<Button
android:id="@+id/sendReceiptBtn"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_marginRight="1dip"
style="@style/DarkButton"
android:text="@string/send_receipt"/>
</LinearLayout>
</RelativeLayout>
以下是例外:
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): FATAL EXCEPTION: main
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bestfitmobile.netsecure/com.bestfitmobile.netsecure.ui.ReceiptActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.os.Looper.loop(Looper.java:130)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at java.lang.reflect.Method.invoke(Method.java:507)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at dalvik.system.NativeStart.main(Native Method)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.Activity.setContentView(Activity.java:1657)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at com.bestfitmobile.netsecure.ui.ReceiptActivity.onCreate(ReceiptActivity.java:54)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): ... 11 more
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): Caused by: java.lang.reflect.InvocationTargetException
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at java.lang.reflect.Constructor.constructNative(Native Method)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): ... 21 more
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.content.res.Resources.loadDrawable(Resources.java:1709)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.View.<init>(View.java:1951)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.View.<init>(View.java:1899)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.view.ViewGroup.<init>(ViewGroup.java:286)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): ... 24 more
答案 0 :(得分:1)
答案在这里:
07-11 07:08:01.040: ERROR/AndroidRuntime(15635): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
名为background
的drawable太大了。如果你删除它应该加载正常。不确定它有多大,但显然你使用的图像太大了。