gpt4 book ai didi

java - R.id.container 未解析

转载 作者:太空狗 更新时间:2023-10-29 22:52:43 25 4
gpt4 key购买 nike

我买了 Bill Phillips 和 Brian Hardy 的书“Android 编程大 Nerd 牧场指南”。在第一章中,我使用 idea 而不是 eclipse 创建了 Gradle 解决方案。 idea生成的这个项目编译不通过。

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new DummyFragment())
.commit();
}
}

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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".QuizActivity$DummyFragment">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

错误:找不到符号变量容器

我没有改变任何东西,但是项目没有编译

请帮帮我。

最佳答案

正如我在评论中提到的,您必须在布局中添加以下代码:

 android:id = "@+id/container" 

你得到这个错误是因为你的 xml 文件中没有 container id

关于java - R.id.container 未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com