我的活动一直在崩溃,这只是在UI上显示的文字,请告诉我我做错了什么。这是在XML文件中显示错误但是根据我的XML文件很好,我无法找到XML文件中的错误。 这是我的代码
public class PlacedOrderConfirmation extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.place_order_confirmation);
TextView placed_successful_txt= (TextView)findViewById(R.id.placed_successful_txt);
Intent intent = getIntent();
String edit_order_id = intent.getStringExtra("EDIT_OR_PLACE") != null ? intent.getStringExtra("EDIT_OR_PLACE") : "";
if(edit_order_id!=null && edit_order_id.length()>0){
placed_successful_txt.setText("YOUR ORDER HAS BEEN\nUPDATED SUCCESSFULLY");
}
Button notification_icon = (Button) findViewById(R.id.notification_icon);
ImageView btnContinue = (ImageView) findViewById(R.id.cont);
notification_icon.getLayoutParams().height = (int) (Utility.getDeviceHeight(this) * .04);
notification_icon.getLayoutParams().width = (int) (Utility.getDeviceHeight(this) * .04);
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(PlacedOrderConfirmation.this, ContractorDashboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
});
}
}
XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_summary"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/confirmation"
android:textColor="@color/white"
android:textSize="@dimen/medium_text" />
<Button
android:id="@+id/notification_icon"
android:layout_width="wrap_content"
android:visibility="invisible"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:background="@drawable/notification_icon" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/congratulation"
android:textSize="42sp"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"/>
<TextView
android:id="@+id/placed_successful_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/orderplaced"
android:textSize="@dimen/text_large"
android:textStyle="bold"
android:layout_margin="20dp"
android:textColor="@color/green"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/emailsent"
android:textSize="@dimen/text_small"
android:layout_marginTop="20dp"
android:textColor="@color/gray_base"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="40dp"
android:text="@string/click"
android:textSize="@dimen/text_large"
android:layout_centerVertical="true"
android:textColor="@color/white"
/>
<ImageView
android:layout_width="70dp"
android:layout_height="35dp"
android:id="@+id/cont"
android:layout_marginTop="10dp"
android:background="@drawable/forward_arrow"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
这是logcat
10-20 10:48:08.394 24918-24918/com.loadarmy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.loadarmy, PID: 24918
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.loadarmy/com.loadarmy.contractor.PlacedOrderConfirmation}: android.view.InflateException: Binary XML file line #89: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #89: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:623)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:597)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:601)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:434)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.createFromResourceStream(Resources.java:2503)
at android.content.res.Resources.loadDrawable(Resources.java:2155)
at android.content.res.MiuiResources.loadDrawable(MiuiResources.java:393)
at android.content.res.Resources.loadDrawable(Resources.java:2062)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3558)
at android.widget.ImageView.<init>(ImageView.java:123)
at android.widget.ImageView.<init>(ImageView.java:119)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:597)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
您可以将背景图像设置为xml的LinearLayout和Button。其中一张图片正在尝试缩小图片尺寸或更改图片。
答案 1 :(得分:1)
您正在 OutOfMemoryError
当Java虚拟机无法分配对象时抛出,因为 内存不足,没有更多的内存可供使用 垃圾收集器。
此错误显示应用程序何时尝试将更多数据添加到堆空间区域,但没有足够的空间。
首先降低图片分辨率,然后在清单中设置android:largeHeap="true"
。