在应用程序中,我将数据从一个活动传递到另一个活动。在第二个活动中,我收到此错误
06-18 11:32:58.187: W/dalvikvm(560): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-18 11:32:58.217: E/AndroidRuntime(560): FATAL EXCEPTION: main
06-18 11:32:58.217: E/AndroidRuntime(560): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.edit_order}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.os.Looper.loop(Looper.java:123)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-18 11:32:58.217: E/AndroidRuntime(560): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 11:32:58.217: E/AndroidRuntime(560): at java.lang.reflect.Method.invoke(Method.java:507)
06-18 11:32:58.217: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-18 11:32:58.217: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-18 11:32:58.217: E/AndroidRuntime(560): at dalvik.system.NativeStart.main(Native Method)
06-18 11:32:58.217: E/AndroidRuntime(560): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
06-18 11:32:58.217: E/AndroidRuntime(560): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3694)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1400)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1326)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:47)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.rInflate(LayoutInflater.java:625)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-18 11:32:58.217: E/AndroidRuntime(560): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.Activity.setContentView(Activity.java:1657)
06-18 11:32:58.217: E/AndroidRuntime(560): at com.example.project.edit_order.onCreate(edit_order.java:42)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 11:32:58.217: E/AndroidRuntime(560): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-18 11:32:58.217: E/AndroidRuntime(560): ... 11 more
FROM THIS链接我发现至少有一个布局应该
android:layout_width="fill_parent"
android:layout_height="fill_parent"
,我的布局也存在问题
我的XML IS
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" >
<include layout="@layout/footer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="460dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/background2"
android:minHeight="400dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/bar" >
<Button
android:id="@+id/back"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/left" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:text="Order"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Oder ID"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/OrderId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
android:textColor="@android:color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/OrderPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
android:textColor="@android:color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Date"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/OrderDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="TextView"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/OrderStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
android:textColor="@android:color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/OrderTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="272dp"
android:src="@drawable/bakery2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<Button
android:id="@+id/back"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Back" />
<Button
android:id="@+id/CancelOrder"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginRight="@id/back"
android:text="Cancel Order" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
使用一个父布局并将所有XML代码放在该父布局中。我希望它能解决你的问题