android包含标签 - 无效的布局参考
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2533972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android include tag - invalid layout reference
提问by Dalibor Frivaldsky
I'm having a problem including a different layout through the include tag in the android layout xml file. When specifing the layout reference ( @layout/... ), i'm getting a InflateException in the Eclipse ADT with the following error: InflateException: You must specifiy a valid layout reference. The layout ID @layout/func_edit_simple_calculator_toolbox is not valid.
我在通过 android 布局 xml 文件中的 include 标记包含不同的布局时遇到问题。在指定布局引用 (@layout/...) 时,我在 Eclipse ADT 中收到 InflateException 并显示以下错误: InflateException: You must specifiy a valid layout reference。布局 ID @layout/func_edit_simple_calculator_toolbox 无效。
the reference should be valid, as I've selected it from the the list of my other layouts and didnt type it in. I'm using android sdk v2.1
参考应该是有效的,因为我从我的其他布局列表中选择了它并且没有输入它。我使用的是 android sdk v2.1
these are the layout files
这些是布局文件
func_edit_simple_calculator_toolbox.xml
func_edit_simple_calculator_toolbox.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"></Button>
<Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+"></Button>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4"></Button>
<Button android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5"></Button>
<Button android:id="@+id/Button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6"></Button>
<Button android:id="@+id/Button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-"></Button>
</TableRow>
</TableLayout>
function_editor_layout.xml
function_editor_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.calculoid.FunctionView android:id="@+id/function_view" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
<include android:id="@+id/include01" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/func_edit_simple_calculator_toolbox"></include>
</LinearLayout>
Does any one know what could be the problem?
有谁知道可能是什么问题?
thanks in advance
提前致谢
回答by cottonBallPaws
If anyone stumbles upon this thread looking for this error:
如果有人偶然发现此线程以查找此错误:
Caused by: android.view.InflateException: You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />
Make sure you do:
确保你这样做:
<include layout="@layout/your_layout" />
<include layout="@layout/your_layout" />
and not:
而不是:
<include android:layout="@layout/your_layout" />
<include android:layout="@layout/your_layout" />
layout
should nothave android:
in front of it.
layout
应该不会有android:
在它的前面。
回答by ggomeze
I think i should mention how i solved the same problem. Tried cleaning the project and didn't work. I have quite large names for the layout (chrono_first_small_field), and that wasn't the cause either.
我想我应该提到我是如何解决同样的问题的。尝试清理项目,但没有奏效。我有相当大的布局名称(chrono_first_small_field),这也不是原因。
Closed Eclipse, and just opened it again, and that worked.
关闭 Eclipse,然后再次打开它,就可以了。
That makes more sense than having to implement the onMeasure method :-)
这比必须实现 onMeasure 方法更有意义:-)
回答by Steve Haley
I don't see anything immediately wrong with that, so that's a bit odd. I can only think of two things: 1) Have you tried using a shorter file name? There are a few restrictions on what's acceptable in a file name, e.g. no uppercase characters or symbols, in order to ensure compatibility and file name length might be one of them. 2) Have you tried removing some of your android:... statements in the include, and leaving it at just <include layout="@layout/..."/>
? You don't actually need to specify its height and width in the include as that's already defined in the imported layout file.
我没有立即看到任何错误,所以这有点奇怪。我只能想到两件事:1)您是否尝试过使用较短的文件名?对于文件名中可接受的内容有一些限制,例如不能使用大写字符或符号,以确保兼容性,文件名长度可能是其中之一。2)你有没有尝试删除一些你的android:...报表中包括,在刚刚离开它<include layout="@layout/..."/>
?您实际上不需要在包含中指定其高度和宽度,因为这已在导入的布局文件中定义。
回答by Dalibor Frivaldsky
I've "solved" the problem, but I dont know what really helped. My layout files did not went through any major rewrite and practically contain the same. The only notable change I've done before the problem went away was to override the onMeasure( int, int ) method in my custom view class, with the implementation just calling setMeasuredDimension( 100, 100 ).
我已经“解决”了这个问题,但我不知道什么真正有帮助。我的布局文件没有经过任何重大的重写,实际上包含相同的内容。在问题消失之前,我所做的唯一显着更改是在我的自定义视图类中覆盖 onMeasure( int, int ) 方法,实现只是调用 setMeasuredDimension( 100, 100 )。
回答by mrBorna
launch eclipse with the -cleanoption and your problem is fixed guaranteed. It will take about 30 seconds longer to launch though
与启动Eclipse -clean选项,你的问题是固定的保证。启动需要大约 30 秒的时间
回答by dwbrito
Check for empty
检查是否为空
<include> </include>
<include> </include>
tags, (probably caused by automatic code formatting).
标签,(可能是由自动代码格式化引起的)。
They can appear somewhere 'hidden' in your xml.
它们可以出现在您的 xml 中“隐藏”的某个地方。
回答by Victor Chelaru
For those using Xamarin Studio - I added a bunch of AXML files from a different project, and also was getting the exact same error. I simply shut down and restarted Xamarin Studio (PC) and this also solved the problem. It's interesting that a different IDE has the same issue.
对于那些使用 Xamarin Studio 的人 - 我从不同的项目中添加了一堆 AXML 文件,并且也得到了完全相同的错误。我只是关闭并重新启动 Xamarin Studio (PC),这也解决了问题。有趣的是,不同的 IDE 也有同样的问题。
回答by Lorenzo Barbagli
For me the problem was that the name of the layout was wrong: I used "-" instead of "_". AndroidStudio didn't tell me somthing was wrong till I tried to deploy the app
对我来说,问题是布局的名称是错误的:我使用了“-”而不是“_”。在我尝试部署应用程序之前,AndroidStudio 并没有告诉我有什么问题