6

When I create this new class Quake and try to write some code in it ,it displays the following message, enter image description here

and when I try to run it Android Studio automatically delete the class Quake.

enter image description here

Can someone explain me why is this happening and how to resolve it ?

Prateek Joshi
  • 3,929
  • 3
  • 41
  • 51

2 Answers2

6

You're in Packages view and putting all your files in the wrong folder. Switch to Project view (left hand, top side toggle). Under app, you should see a folder called src -> main -> java -> com.example.prateek. That's where all your class files should properly be to avoid autodeletion.

Matter Cat
  • 1,538
  • 1
  • 14
  • 23
0

This happens due to incorrect Source folder mappings done by some mistake.

In order to resolve the same, please go to

Project Structure -> Project Settings -> Modules.
  1. Select the Module that has this issue and select the Sources Tab

  2. On the Right Hand Side you will find Add Content Root pane. Please Check if the Source and Test Folders are mapping to the correct root and there is no other mapping present apart from the valid root mapping [For eg src for Source Folders and tst for Test Source Folders.]

  3. Delete any unwanted mapping present in either of them. Apply and Re sync the project.

Issue should be solved now.

Rohit Mishra
  • 281
  • 5
  • 16