不幸的是项目停止了 - 错误

时间:2013-04-02 15:35:09

标签: android android-layout android-button

我是Java新手以及所有这些东西,我不知道(即使在观看了数百个教程和数百个阅读教程之后)我做错了什么。

好吧,我想制作一个应用程序,它可以为我的所有衣服编制目录。

我已经制作了4个imageButtons,一个导致新活动(文件存在)和3个空活动。 enter image description here

我想在模拟器上尝试使用imageButton1,但每当我打开应用程序时,都会显示一个空白页面,几秒钟后它就崩溃了(“不幸的是应用程序停止了”)。 有时甚至发射器停止。

你知道吗,我做错了什么?

这是我的主要xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="324dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="130dp"
                android:layout_height="127dp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:src="@drawable/view" android:contentDescription="@string/todo"/>

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="117dp"
                android:layout_height="122dp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:src="@drawable/wishlist" />
        </LinearLayout>

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.74" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="       My Closet"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#610B5E" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/_wishlist"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#610B5E" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageButton
                    android:id="@+id/imageButton3"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:scaleType="centerCrop"
                    android:src="@drawable/calculator" />

                <ImageButton
                    android:id="@+id/imageButton4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:scaleType="centerCrop"
                    android:src="@drawable/laundry" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="      Calculator"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#610B5E" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="           Laundry"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#610B5E" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

            </TableRow>

        </TableLayout>
    </LinearLayout>

</RelativeLayout>

我的logcat:

04-02 14:56:01.615: E/Trace(691): error opening trace file: No such file or directory (2)
04-02 14:56:02.655: D/AndroidRuntime(691): Shutting down VM
04-02 14:56:02.655: W/dalvikvm(691): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
04-02 14:56:02.696: E/AndroidRuntime(691): FATAL EXCEPTION: main
04-02 14:56:02.696: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blogspot.ladyricecake.www/com.blogspot.ladyricecake.www.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.os.Looper.loop(Looper.java:137)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread.main(ActivityThread.java:4745)
04-02 14:56:02.696: E/AndroidRuntime(691):  at java.lang.reflect.Method.invokeNative(Native Method)
04-02 14:56:02.696: E/AndroidRuntime(691):  at java.lang.reflect.Method.invoke(Method.java:511)
04-02 14:56:02.696: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-02 14:56:02.696: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-02 14:56:02.696: E/AndroidRuntime(691):  at dalvik.system.NativeStart.main(Native Method)
04-02 14:56:02.696: E/AndroidRuntime(691): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
04-02 14:56:02.696: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-02 14:56:02.696: E/AndroidRuntime(691):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.Activity.setContentView(Activity.java:1867)
04-02 14:56:02.696: E/AndroidRuntime(691):  at com.blogspot.ladyricecake.www.MainActivity.onCreate(MainActivity.java:16)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.Activity.performCreate(Activity.java:5008)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-02 14:56:02.696: E/AndroidRuntime(691):  ... 11 more
04-02 14:56:02.696: E/AndroidRuntime(691): Caused by: java.lang.reflect.InvocationTargetException
04-02 14:56:02.696: E/AndroidRuntime(691):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-02 14:56:02.696: E/AndroidRuntime(691):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
04-02 14:56:02.696: E/AndroidRuntime(691):  ... 23 more
04-02 14:56:02.696: E/AndroidRuntime(691): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x5/d=0x1001 a=2 r=0x7f040000}
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.content.res.Resources.loadDrawable(Resources.java:1892)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.View.<init>(View.java:3336)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.View.<init>(View.java:3273)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.view.ViewGroup.<init>(ViewGroup.java:421)
04-02 14:56:02.696: E/AndroidRuntime(691):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
04-02 14:56:02.696: E/AndroidRuntime(691):  ... 26 more
04-02 14:56:07.945: I/Process(691): Sending signal. PID: 691 SIG: 9

1 个答案:

答案 0 :(得分:3)

最低Caused by读取:

android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x5/d=0x1001 a=2 r=0x7f040000}

引导我到你的RelativeLayout。您已将尺寸指定为background,它需要一个Drawable:

android:background="@dimen/activity_horizontal_margin"

<击>