12

Seem to be getting this occurring error whenever I run my android application.

The only way to get around it is by rebuilding the project and runs normally again.

If anyone knows the reason for this will be much appreciated

dave o grady
  • 788
  • 8
  • 12
  • related: https://stackoverflow.com/questions/13811020/error-class-x-is-public-should-be-declared-in-a-file-named-x-java – starball Apr 23 '23 at 22:54

4 Answers4

9

Try Build -> Clean Project Then Build -> Make Project

Allen M.
  • 91
  • 1
  • 2
  • 2
    this answer solved my issue but when i get every build error ,i always get again same issue. can i find permanent answer? – ozanurkan Nov 16 '20 at 22:49
  • 1
    **GREAT answer, it worked!** After upgrading to Android Studio Arctic Fox, I kept getting this problem and couldn't figure out how to solve the problem. Thank you! – floki1 Dec 18 '21 at 19:21
6

Faced the same issue when ever tried to install the App,

Build -> Clean Project Then Build -> Make Project

even though problem arises again and again then go with the below steps.

Delete .gradle Folder within android Directory

Now, click Run it works fine.

Sunil KV
  • 763
  • 9
  • 13
3

For Flutter users,

  1. Execute Flutter Clean in terminal of your project folder.
  2. Run flutter pub get to get all packages.
  3. Run your project.

Although, the problem arises everytime I try to run the project. This problems arises after I added a package in my project. So, that package might be causing some problem.

Priyansh jain
  • 1,065
  • 10
  • 17
0

Under your Project view in Android Studio navigate to the .gradle folder.

In that folder, if you see more than one version of gradle, such as, for example, 7.0.2 and 6.1.0.

Delete one of the versions, preferably the lower version.

Clean, build, and you run.

It should run each time without the error, or the necessity to clean and build.

M Jesse
  • 2,213
  • 6
  • 31
  • 37