gpt4 book ai didi

java - 找不到符号 findViewById

转载 作者:行者123 更新时间:2023-12-01 18:11:15 25 4
gpt4 key购买 nike

我做错了什么,我检查了几次ID,在XML中一切正常,但是当我想构建发布应用程序时,会出现此错误,当我构建调试应用程序时,我不会出现此错误。

error: cannot find symbol
notifications = findViewById(R.id.notification_text);
^
symbol: variable notification_text

主要 Activity

public class MainActivity extends AppCompatActivity  {
TextView notifications;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavigation = findViewById(R.id.bottom_navigation);
bottomNavigation.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
notifications = findViewById(R.id.notification_text);
}
}

activity_main.xml

<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:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:windowTranslucentNavigation="false"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/BottomLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/swipeRefresh">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@drawable/border_top_bottom_menu"
android:clipToPadding="false"
android:foreground="@android:color/transparent"
android:foregroundTint="@android:color/transparent"
android:isScrollContainer="true"
android:theme="@style/bottom_navigation_menu"
android:visibility="visible"
app:barrierAllowsGoneWidgets="false"
app:elevation="0dp"
app:itemHorizontalTranslationEnabled="false"
app:itemIconSize="22dp"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toTopOf="@id/notification_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
<TextView
android:id="@+id/notification_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:background="@color/notification_offline"
android:fontFamily="@font/roboto"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textIsSelectable="false"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bottom_navigation" />

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

应用程序在模拟器上运行良好,我没有任何错误,并且 notification_text 也按我的预期运行。问题仅在我尝试构建发布应用程序时出现。

编辑:导入

package com.android.app_name;    
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import androidx.annotation.IdRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.ContextCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Looper;
import android.os.StrictMode;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Handler;
import com.androidstudy.networkmanager.Monitor;
import com.androidstudy.networkmanager.Tovuti;
import com.github.javiersantos.appupdater.enums.UpdateFrom;
import com.github.javiersantos.appupdater.enums.Display;
import com.github.javiersantos.appupdater.AppUpdater;
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import android.content.Intent;
import androidx.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.net.Uri;
import android.webkit.ValueCallback;
import android.os.Build;
import android.content.ActivityNotFoundException;
import android.app.DownloadManager;
import android.os.Environment;
import android.content.pm.PackageManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

最佳答案

我在导入中找不到您对 R 的导入。尝试清理你的项目,然后重建它。你也可能以某种方式从错误的包中导入 R。我以前遇到过另一个导入有 R 包的情况,因此我没有收到没有导入包的错误。重新检查您的导入,也许选择所有导入执行 cmd+x (MACOS)/ctrl+x (WIN),然后首先导入 R 包,然后 ctrl+v(WIN)/cmd+v(MACOS) 您的导入。这样也能解决。如果有效请告诉我!

关于java - 找不到符号 findViewById,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60465878/

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