Android Studio 拒绝运行 main() [英] Android Studio refuses to run main()
问题描述
重现步骤:
- 在 Android Studio 中启动一个新项目(带有最新更新);
- 创建一个新类并像往常一样添加 main();
- 右键单击类以运行 main() 作为测试.
package test;
public class Test {
public static void main(String[] args) {
}
}
通常我希望我可以 System.out.printLn("Hello World")
但这一次,无论是新项目,我都会收到以下错误:
Usually I expect I can just System.out.printLn("Hello World")
but this time, no matter if it's a new project, I get the following error:
2:34:23 PM: Executing task 'Test.main()'...
Executing tasks: [Test.main()] in project C:\Users\regan\Desktop\events\MyApplication
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\regan\AppData\Local\Temp\Test_main__2.gradle' line: 20
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Test.main()'.
> SourceSet with name 'test' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
2:34:24 PM: Task execution finished 'Test.main()'.
在 Unity 中使用了多年 C# 之后,我 相当 对 Java 不熟悉,并且不知道所有这些东西试图告诉我什么.我用谷歌搜索过,但我发现最接近的是一种隐藏此错误的方法(假设代码仍在编译).我至少需要这段代码才能编译.
I am fairly new to Java after years of C# in Unity and have no idea what all this stuff is trying to tell me. I have googled but the closest I found was a way to HIDE this error (assuming code was still compiling). I need this code to at least compile.
推荐答案
快速修复:您可以使用Run with Coverage..见下图.
Quick Fix : You can run using Run with Coverage.. See Image Below.
永久解决方案:添加
在路径 E:\Project\.idea\gradle.xml
下的文件 gradle.xml
内.见下图.
inside File gradle.xml
under path E:\Project\.idea\gradle.xml
. See Image below.
这篇关于Android Studio 拒绝运行 main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!