【问题标题】:Unable to find symbol error when adding a new view to xml向 xml 添加新视图时找不到符号错误
【发布时间】:2021-10-13 10:48:17
【问题描述】:

我最近将我的工作室升级为北极狐。我正在尝试在我的 xml 中进行更改并添加 textView 但我收到此错误:

error: cannot find symbol
        binding.tvUserBio2.setText("LETS MAKE THIS HAPPEN");
               ^
  symbol:   variable tvUserBio2
  location: variable binding of type FragmentProfileBinding

我尝试清理构建、无效和缓存工作室,但仍然无法正常工作。有人可以帮忙吗?

这是我的 XML。我尝试在 XML 中的任何位置添加任何文本视图,我得到了同样的错误。

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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"
    android:background="@color/ui_background">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="24dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/constraint_layout_profile_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:paddingBottom="21dp"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <com.google.android.material.imageview.ShapeableImageView
                android:id="@+id/iv_user_profile_pic"
                android:layout_width="104dp"
                android:layout_height="104dp"
                android:src="@drawable/placeholder_profile"
                app:layout_constraintBottom_toBottomOf="@id/level_progress_bar"
                app:layout_constraintLeft_toLeftOf="@id/level_progress_bar"
                app:layout_constraintRight_toRightOf="@id/level_progress_bar"
                app:layout_constraintTop_toTopOf="@id/level_progress_bar"
                app:shapeAppearanceOverlay="@style/CircularImageView" />

            <ProgressBar
                android:id="@+id/level_progress_bar"
                style="@style/CircularDeterminateProgressBar"
                android:layout_width="157dp"
                android:layout_height="157dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:progress="60" />

            <TextView
                android:id="@+id/tv_profile_user_name"
                style="@style/SemiBoldFont.Size16_Body"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="11dp"
                android:layout_marginRight="16dp"
                android:ellipsize="marquee"
                android:gravity="center"
                android:lineSpacingExtra="-10dp"
                android:maxLines="3"
                android:textColor="@color/gray_30_3B4345"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/level_progress_bar"
                tools:text="Impact\nUser" />

            <androidx.appcompat.widget.LinearLayoutCompat
                android:id="@+id/constraint_layout_user_titles"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center"
                app:layout_constraintLeft_toLeftOf="@id/guideline_middle"
                app:layout_constraintRight_toRightOf="@id/guideline_middle"
                app:layout_constraintTop_toBottomOf="@id/tv_profile_user_name">

                <TextView
                    android:id="@+id/tv_user_top_1_per"
                    style="@style/RegularFont.Size10_Caption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="4dp"
                    android:background="@drawable/button_rounded_corner_border_bg"
                    android:paddingLeft="8dp"
                    android:paddingTop="4dp"
                    android:paddingRight="8dp"
                    android:paddingBottom="4dp"
                    android:textColor="@color/blue_40_0091B6"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:text="TOP 1%" />

                <TextView
                    android:id="@+id/tv_user_title"
                    style="@style/RegularFont.Size10_Caption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginRight="4dp"
                    android:background="@drawable/button_rounded_corner_border_bg"
                    android:paddingLeft="8dp"
                    android:paddingTop="4dp"
                    android:paddingRight="8dp"
                    android:paddingBottom="4dp"
                    android:textAllCaps="true"
                    android:textColor="@color/blue_40_0091B6"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    tools:text="HERO FOR RUN" />

                <TextView
                    android:id="@+id/tv_user_current_streak"
                    style="@style/RegularFont.Size10_Caption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="4dp"
                    android:background="@drawable/button_rounded_corner_bg_f2f3f4"
                    android:drawablePadding="4dp"
                    android:paddingLeft="8dp"
                    android:paddingTop="4dp"
                    android:paddingRight="8dp"
                    android:paddingBottom="4dp"
                    android:textAllCaps="true"
                    android:textColor="@color/red_60_F55A33"
                    app:drawableEndCompat="@drawable/ic_streak_icon"
                    tools:text="99999" />

            </androidx.appcompat.widget.LinearLayoutCompat>

            <TextView
                android:id="@+id/tv_user_bio"
                style="@style/RegularFont.Size12_Caption"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_marginTop="10dp"
                android:layout_marginRight="30dp"
                android:gravity="center"
                android:lineSpacingExtra="-8dp"
                android:textColor="@color/gray_60_919DA1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/constraint_layout_user_titles"
                tools:text="100 pushups, 100 sit-ups, 100 squats\nand a 10km run!" />

            <TextView
                android:id="@+id/tv_user_bio_2"
                style="@style/RegularFont.Size12_Caption"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_marginTop="10dp"
                android:layout_marginRight="30dp"
                android:gravity="center"
                android:lineSpacingExtra="-8dp"
                android:textColor="@color/gray_60_919DA1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/tv_user_bio"
                tools:text="100 pushups, 100 sit-ups, 100 squats\nand a 10km run!" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_middle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.5" />


            <TextView
                android:id="@+id/tv_user_impact"
                style="@style/SemiBoldFont.Size20_Heading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:textColor="@color/gray_30_3B4345"
                app:layout_constraintLeft_toLeftOf="@+id/guideline_middle"
                app:layout_constraintRight_toRightOf="@+id/guideline_middle"
                app:layout_constraintTop_toBottomOf="@+id/tv_user_bio"
                tools:text="₹20,000" />

            <TextView
                android:id="@+id/tv_donated_caption"
                style="@style/RegularFont.Size10_Caption.Profile_Impact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/profile_caption_donated"
                app:layout_constraintLeft_toLeftOf="@+id/guideline_middle"
                app:layout_constraintRight_toRightOf="@+id/guideline_middle"
                app:layout_constraintTop_toBottomOf="@+id/tv_user_impact" />

            <TextView
                android:id="@+id/tv_user_distance"
                style="@style/MediumFont.Size14_Body.Profile_Impact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="@+id/tv_user_impact"
                app:layout_constraintLeft_toLeftOf="@+id/tv_distance_caption"
                app:layout_constraintRight_toRightOf="@+id/tv_distance_caption"
                app:layout_constraintTop_toTopOf="@+id/tv_user_impact"
                tools:text="20000 km"

                />

            <TextView
                android:id="@+id/tv_distance_caption"
                style="@style/RegularFont.Size10_Caption.Profile_Impact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/profile_caption_distance"
                app:layout_constraintHorizontal_bias="0.4"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@id/tv_donated_caption"
                app:layout_constraintTop_toTopOf="@id/tv_donated_caption" />

            <TextView
                android:id="@+id/tv_user_max_streak"
                style="@style/MediumFont.Size14_Body.Profile_Impact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="@+id/tv_user_impact"
                app:layout_constraintLeft_toLeftOf="@+id/tv_max_streak_caption"
                app:layout_constraintRight_toRightOf="@+id/tv_max_streak_caption"
                app:layout_constraintTop_toTopOf="@+id/tv_user_impact"
                tools:text="20000" />

            <TextView
                android:id="@+id/tv_max_streak_caption"
                style="@style/RegularFont.Size10_Caption.Profile_Impact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/profile_caption_max_streak"
                app:layout_constraintHorizontal_bias="0.6"
                app:layout_constraintLeft_toRightOf="@+id/guideline_middle"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tv_user_impact" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.cardview.widget.CardView
            android:id="@+id/card_view_profile_achievements"
            style="@style/CardView_Profile_Background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/constraint_layout_profile_header">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_achievement_card_title"
                    style="@style/SemiBoldFont.Size14_Body.Profile_Card_Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_achievements_title"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btn_achievement_see_more"
                    style="@style/SemiBoldFont.Size8_Caption.Profile_Card_Button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_see_more_button_text"
                    app:layout_constraintBottom_toBottomOf="@+id/tv_achievement_card_title"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/tv_achievement_card_title" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_achievements"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_achievement_card_title" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/card_view_profile_in_progress"
            style="@style/CardView_Profile_Background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentPadding="0dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/card_view_profile_achievements">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_in_progress_title"
                    style="@style/SemiBoldFont.Size14_Body.Profile_Card_Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:text="@string/profile_in_progress_title"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/btn_in_progress_see_more"
                    style="@style/SemiBoldFont.Size8_Caption.Profile_Card_Button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:text="@string/profile_see_more_button_text"
                    app:layout_constraintBottom_toBottomOf="@+id/tv_in_progress_title"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/tv_in_progress_title" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_in_progress"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_in_progress_title" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/card_view_profile_steps"
            style="@style/CardView_Profile_Background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/card_view_profile_in_progress">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_steps_title"
                    style="@style/SemiBoldFont.Size14_Body.Profile_Card_Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawablePadding="12dp"
                    android:text="@string/profile_steps_title"
                    app:drawableLeftCompat="@drawable/ic_profile_steps_icon"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/tv_steps_date"
                    style="@style/MediumFont.Size12_Caption"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_steps_title"
                    android:textColor="@color/gray_50_75858A"
                    app:layout_constraintBottom_toBottomOf="@id/tv_steps_title"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@id/tv_steps_title"
                    tools:text="04th july '21, Sun" />

                <Button
                    android:id="@+id/btn_steps_see_more"
                    style="@style/SemiBoldFont.Size8_Caption.Profile_Card_Button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_see_more_button_text"
                    app:layout_constraintBottom_toBottomOf="@+id/tv_steps_title"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/tv_steps_title" />

                <com.github.mikephil.charting.charts.BarChart
                    android:id="@+id/steps_bar_chart"
                    android:layout_width="0dp"
                    android:layout_height="150dp"
                    app:layout_constraintLeft_toLeftOf="@id/tv_steps_title"
                    app:layout_constraintRight_toRightOf="@id/btn_steps_see_more"
                    app:layout_constraintTop_toBottomOf="@+id/tv_steps_title"
                    android:layout_marginTop="20dp"
                    android:visibility="gone"
                    />
                <TextView

                    android:id="@+id/my_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <LinearLayout
                    android:id="@+id/steps_bar_chart_layout"
                    android:layout_width="0dp"
                    android:layout_height="150dp"
                    app:layout_constraintLeft_toLeftOf="@id/tv_steps_title"
                    app:layout_constraintRight_toRightOf="@id/btn_steps_see_more"
                    app:layout_constraintTop_toBottomOf="@+id/tv_steps_title"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal"
                    ></LinearLayout>

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/card_view_profile_recent_workout"
            style="@style/CardView_Profile_Background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/card_view_profile_steps">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_recent_workout_title"
                    style="@style/SemiBoldFont.Size14_Body.Profile_Card_Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_recent_workout_title"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/btn_recent_workout_see_more"
                    style="@style/SemiBoldFont.Size8_Caption.Profile_Card_Button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_see_more_button_text"
                    app:layout_constraintBottom_toBottomOf="@+id/tv_recent_workout_title"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/tv_recent_workout_title" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_recent_workout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_recent_workout_title" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/card_view_profile_charity_overview"
            style="@style/CardView_Profile_Background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/card_view_profile_recent_workout">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_charity_overview_title"
                    style="@style/SemiBoldFont.Size14_Body.Profile_Card_Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_charity_overview_title"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/btn_charity_overview_see_more"
                    style="@style/SemiBoldFont.Size8_Caption.Profile_Card_Button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/profile_see_more_button_text"
                    app:layout_constraintBottom_toBottomOf="@+id/tv_charity_overview_title"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/tv_charity_overview_title" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_charity_overview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_charity_overview_title" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

【问题讨论】:

  • 你能分享你的xml吗?
  • @KamalNayan 添加了
  • 你的 Android Studio 是什么版本的?
  • @KamalNayan 2020.3.1 补丁 3
  • 我的也是这样,但我没有遇到这个问题。所以我认为这个问题与android studio的版本无关

标签: android android-layout


【解决方案1】:

您的 xml 中只有 tv_user_bio。这意味着 binding.tvUserBio。为什么你把 2, tvUserBio2 的变量结尾?

【讨论】:

  • 已进行编辑。抱歉,XML 错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-10
相关资源
最近更新 更多