4

I am new to the forum and just started learning about Android app development. I was going through the tutorials at developer.android.com and already ran into an compiling error. I see these three errors on my activity_main.xml:

error: Error: String types not allowed (at 'layout_height' with value 'wrap content').  activity_main.xml   
error: Error: String types not allowed (at 'layout_width' with value 'wrap content').   activity_main.xml   
error: Error: String types not allowed (at 'layout_height' with value 'wrap content').  activity_main.xml

and here is my activity_main.xml code as of now:

<LinearLayout 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:orientation="horizontal"
    tools:context=".MainActivity" >

    <EditText android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap content"
        android:layout_height="wrap content"
        android:text="@string/button_send" />

</LinearLayout>

Is it throwing an error because wrap_content is an incorrect syntax or does it need to be declared elsewhere? Any help will be appreciated on how to troubleshoot or fix this.

Thanks!

4

5 回答 5

11

我刚开始自学。我相信问题是缺少下划线。它应该是“wrap_content”而不是“wrap content”。

于 2013-07-14T16:34:17.130 回答
2

wrap_content不是wrap content。_ 改变它,你的问题应该早就消失了!

于 2013-07-14T16:41:44.733 回答
1

必须 wrap_content 代替 wrap content

改变

 <EditText android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap content"
        android:layout_height="wrap content"
        android:text="@string/button_send" />

 <EditText android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" />
于 2013-07-14T16:35:55.223 回答
1

我在 Mac 上评估 Xamarin 时遇到了同样的错误。这是目标框架的问题。我的猜测是某些早期版本的 Android 不支持此 Xml 标记中的所有值,或者 Xamarin 无法正确处理它,或者类似的东西。我将Options->Build->General->Target framework从Android 2.1改成了Android 2.2,之后构建成功。

于 2014-08-17T15:27:07.400 回答
0

我正在输入“warp_content”,这对我来说很糟糕,哈哈。它是“wrap_content”而不是“warp_content”

于 2014-11-15T16:44:26.647 回答