java 生成的源文件不应该被编辑吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30886782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generated source files should not be edited?
提问by Prateek Joshi
When I create this new class
Quakeand try to write some code in it ,it displays the following message,
当我创建这个new class
Quake并尝试在其中编写一些代码时,它显示以下消息,
and when I try to run it
Android Studio automatically delete
the class Quake
.
当我尝试run it
Android Studioautomatically delete
类时Quake
。
Can someone explain me why is this happening and how to resolve it ?
有人能解释一下为什么会发生这种情况以及如何解决吗?
采纳答案by Matter Cat
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.
您正在Packages
查看并将所有文件放在错误的文件夹中。切换到Project
视图(左手,顶部切换)。在 下app
,您应该会看到一个名为src
-> main
-> java
->的文件夹com.example.prateek
。这就是所有类文件都应该正确放置的地方,以避免自动删除。
回答by Mohammad Shahzeb
I faced the same problem. You are making class in test package. See this image, you will be able to make it correct.
我遇到了同样的问题。您正在测试包中制作课程。看到这张图,你就能改正。
回答by Rohit Mishra
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.
Select the Module that has this issue and select the Sources Tab
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.]
Delete any unwanted mapping present in either of them. Apply and Re sync the project.
选择有此问题的模块,然后选择 Sources 选项卡
在右侧,您将找到“添加内容根”窗格。请检查源文件夹和测试文件夹是否映射到正确的根目录,并且除了有效的根映射之外没有其他映射 [例如,源文件夹的 src 和测试源文件夹的 tst。]
删除其中任何一个中存在的任何不需要的映射。应用并重新同步项目。
Issue should be solved now.
问题现在应该解决了。