【问题标题】:can't reference the xml layout in Activity无法在 Activity 中引用 xml 布局
【发布时间】:2020-07-01 10:37:49
【问题描述】:

我遇到了一个问题,我设置了我创建的 activity.xml 的内容视图,但它显示了一些错误。请帮帮我,我还在学习。

这是创建活动时的图像

这是显示错误的图像

这是xml文件 activity_daily_expense_fragment_handler.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".daily_expense_fragment_handler">

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 请检查您导入的 R.
  • 嗨。请勿分享屏幕截图,但请提供错误消息
  • 你能把import R的图片发过来吗?你用android.R导入了吗?如果是,则使用您的包名导入
  • 谢谢我没有导入 R 我现在输入谢谢大家
  • 如果它有效,那么您能接受我的回答吗?

标签: android android-studio android-activity setcontentview


【解决方案1】:

请检查您导入的 R 吗?如果您使用 android.R 导入,则使用您的包名导入。

【讨论】:

    【解决方案2】:

    首先,您应该使用大写字母创建类的名称,例如:DailyExpenseFragmentHandler

    然后检查您的导入。删除您的 R.imported 文件,然后单击布局,然后按 ALT + Enter 自动创建它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多