0

After updating android studio this error appeared to me even though it always worked !!

Suppress: Add @SuppressLint("SuspiciousImport") annotation

What I do not understand is why he never gave it to me before the update !!!

Below I am entering all my imports:

package com.dooale.dooale;

import android.Manifest.permission;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.nfc.Tag;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLng;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.StringTokenizer;

import static android.Manifest.permission.*;
import static android.R.*;

I can not understand

Mark
  • 9,604
  • 5
  • 36
  • 64
Andrea
  • 128
  • 3
  • 13
  • Because you're importing `android.R.*` not your `com.my.package.R.*` which would be the more likely as these would be for imports referencing views, strings, colors, drawables etc .. unique to your app. Sometimes you can think of lint as a co-pilot, other times a back seat driver. – Mark Apr 01 '18 at 11:00
  • Thanks Mark but I did not understand !! sorry but I'm new in android !!! I tried to enter your syntax: com.my.package.R.* , but it does not go !! he corrects me like that : import com.dooale.R.*; or import static android.R.layout;!!! but the problem persists!!! You could not tell me the correct syntax thanks !!! – Andrea Apr 01 '18 at 11:10
  • I have explained why this happened - there is no problem to solve here, it is a lint warning (hence comment not answer). You have used some resources that have been provided with the `android.R` file from the SDK i.e. a standard drawable icon, however a lot of the time your would want to refer to resources from your own project (your own `R` file) - this is simply a lint warning that should be configurable in settings - https://stackoverflow.com/a/16996778/4252352 – Mark Apr 01 '18 at 12:16

1 Answers1

0

R is a generated class that contains IDs of resources. There's one for each of

  • your app project
  • each Android library you add (.aar)
  • Android framework

Typically you

import your.applicationId.R;

because R for your application also includes resource IDs of all libraries.

Resource IDs from the framework android.R are NOT part of your app's R class. They have to be referenced separately.

Because you can only import one class with name R and android.R is shorter than whatever.your.applicationId.is.R the convention is this:

  • import your app's R and reference it like e.g. R.layout.activity_main,
  • DON'T import Android R and reference it fully like e.g. android.R.id.home.
Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • Thank you so much !! but sorry I can not understand !! do not rush to make me a more practical example !!! Excuse me but I'm really down for this situation !!! – Andrea Apr 01 '18 at 15:32
  • Sorry but I know I'm stupid !!!!!! 1 - Because I upgraded android studio that now does not make the app work anymore 2- Because I tried to make your changes but they are not valid and the problem persists !!! – Andrea Apr 01 '18 at 17:55
  • 1
    Alright 1) stop shouting 2) you're not stupid, you're just new 3) screaming "I'm stupid" doesn't make anyone like you more and doesn't help anybody 4) calm down, take a deep breath 5) edit your question and add some code *where you use R*. So far I can't tell, which R you actually need. – Eugen Pechanec Apr 01 '18 at 19:55