Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28268

Disable Android Studio warning: "Access can be ..."

After an update of Android Studio I get warnings on fields like:

public int ex1 = 0;
int ex2 = 0;

or methods or nested classes when they are used only in one class or in the package:

"Access can be private" or "Access can be package-only"

This is can be, and I don't want these warnings but I cannot find how I can deactivate them. Any ideas?

Upvotes: 40

Views: 20408

Answers (3)

Kush Patel
Kush Patel

Reputation: 1251

In Android Studio 2.2.1 open Settings-> Editor -> Inspections. Now go to Java->Declaration redundancy->Declaration Access Can be Weaker and uncheck this option.

Upvotes: 57

Muz
Muz

Reputation: 5980

You can also put this annotation on top of your class:

@SuppressWarnings("WeakerAccess")

Upvotes: 64

Vic
Vic

Reputation: 22041

All you have to do is disable the inspection that fires this warning. Taken from "Suppression Inspections" page in IntelliJ help:

To suppress an inspection in the editor

  1. Set the cursor to the highlighted code issue in the editor.
  2. Press ⌥⏎ or click the light bulb icon to expand the suggestion list.
  3. Depending on the issue, you will see either quick-fixes related to the inspection or the Inspection <inspection name> options item.
  4. Use the up/down arrow keys to select this item and then press the right arrow key or just click the right arrow next to this item.
  5. Pressing the left arrow key, or ⎋ hides the suggestion list. In the inspection options list, select the desired suppress action

    The inspection will be suppressed with special comments in the corresponding piece of code.

Upvotes: 4

Related Questions