Java 错误:不允许使用字符串类型(在';布局高度';带值';换行内容';)。activity_main.xml
我是这个论坛的新手,刚刚开始学习Android应用程序开发。我正在查看developer.android.com上的教程,已经遇到了编译错误。我在activity_main.xml上看到以下三个错误:Java 错误:不允许使用字符串类型(在';布局高度';带值';换行内容';)。activity_main.xml,java,android,xml,Java,Android,Xml,我是这个论坛的新手,刚刚开始学习Android应用程序开发。我正在查看developer.android.com上的教程,已经遇到了编译错误。我在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 (
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
以下是我的activity_main.xml代码:
<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>
它抛出错误是因为wrap_内容的语法不正确,还是需要在其他地方声明?任何关于如何排除故障或修复此问题的帮助都将不胜感激
谢谢 我刚刚开始学习自己。我认为问题在于缺少强调。它应该是“包装内容”而不是“包装内容”。它必须是
包装内容
,而不是包装内容
改变
<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" />
它是包装内容
而不是包装内容
。改变它,你的问题应该早就消失了 我在Mac上评估Xamarin时也遇到了同样的错误。这是目标框架的问题。我的猜测是,Android的某些早期版本不支持这个Xml标记中的所有值,或者Xamarin无法正确处理它,或者类似的东西。我从中更改了选项->构建->常规->目标框架
Android 2.1到Android 2.2,之后构建成功。我输入了“warp\u content”,结果搞砸了,哈哈。这是“wrap\u content”而不是“warp\u content”wrap\u content而不是wrap content我有同样的错误,但我的值是wrap\u content。一切似乎都在正确的语法上。我也犯了这个错误,我的错误是“wrap_content”,字符串的最后一个额外的空格使一切都错了:D,愚蠢的Android Studio,为什么它不能自动修复它:)