【发布时间】:2020-01-04 04:26:45
【问题描述】:
复制步骤:
- 在 Android Studio 中启动一个新项目(使用最新更新);
- 像往常一样创建一个新类并添加 main();
- 右键单击类以运行 main() 作为测试。
package test;
public class Test {
public static void main(String[] args) {
}
}
通常我希望我可以 System.out.printLn("Hello World") 但这一次,无论它是一个新项目,我都会收到以下错误:
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 新手,不知道所有这些东西想告诉我什么。我已经用谷歌搜索了,但我发现最接近的是一种隐藏此错误的方法(假设代码仍在编译)。我至少需要这段代码才能编译。
【问题讨论】:
-
我正在努力解释那个答案。上周我实际上很好地完成了这个过程,但今天我尝试了,在 Android Studio 更新之后,这似乎是唯一的区别。我不知道“子项目{}部分”是什么。
-
这告诉您,您创建了一个 Android 项目,但 Android 应用程序使用 Android 生命周期运行,而不是
main。
标签: java android android-studio gradle