Android链接失败:activity_main.xml中layout_height属性未找到报错求助
ERROR:C:\Users\aron.kibet\AndroidStudioProjects\Status_Saver22\app\src\main\res\layout\activity_main.xml:2: AAPT: error: attribute layout_height (aka com.example.status_saver22:layout_height) not found。
以下是几个直接有效的排查和解决步骤:
检查XML命名空间声明:确保activity_main.xml的根布局标签开头添加了Android核心命名空间,没有这个声明,系统无法识别
layout_height这类标准属性。正确的声明格式如下:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" ...>核对属性拼写:确认第2行的
layout_height没有拼写错误,比如不要写成LayoutHeight、layout_hight这类错误形式,Android的布局属性是全小写且下划线分隔的格式。验证标签类型:检查第2行的控件标签是否为Android标准布局控件(如LinearLayout、ConstraintLayout、RelativeLayout等)。如果是自定义控件,需确认是否错误地给它使用了仅标准控件支持的属性,但
layout_height属于通用属性,这一步主要排除标签本身的语法错误。清理重建项目:有时候Android Studio的缓存会导致这类无厘头的属性识别错误,执行
Build > Clean Project,完成后再执行Build > Rebuild Project,强制重新编译所有资源。
内容的提问来源于stack exchange,提问作者mes

