0

What i'm doing wrong, i have checked few times IDs all is ok in XML but this error comes when i want to build release app, when i'm build debug app then i don't have this error.

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

MainActivity

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>

Also app is working good on emulator i don't have any errors and also notification_text is working as i expect. Problem is only when i try to build release app.

Edit: Imports

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;
LetBit
  • 45
  • 2
  • 5

1 Answers1

0

I can't find your import to R in your imports. try cleaning your project and then rebuilding it.You might also be importing R from the wrong package somehow. It has happened to me before that another import has an R package and thus I don't get the error of no package imported. Re-check your imports, maybe slect all your imports do cmd+x (MACOS)/ctrl+x (WIN), then import first the R package and then ctrl+v(WIN)/cmd+v(MACOS) your imports. That could also solve it. Let me know if it works!

Mateo Hervas
  • 545
  • 1
  • 5
  • 20
  • No it's not a problem there, when i import R studio says unused import with grey color, anyway i was try but not is problem there. Also this happend only for TextView and this ID all other is working fine. – LetBit Feb 29 '20 at 15:39