我试图通过Android Studio运行一个简单的程序,但出现以下错误(如下)。 我读过有关更改与SDK和gradle相关的某些内容的信息,但我不知道这正是我的问题,也无法解决。有人可以说出真正的问题是什么,我该如何解决? 错误是:
Executing tasks: [MainC.main()] in project
C:\Users\Admin\AndroidStudioProjects\SomeProject
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\Admin\AppData\Local\Temp\MainC_main__.gradle' line: 20
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:MainC.main()'.
> SourceSet with name 'main' 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
12:31:58: Task execution finished 'MainC.main()'.
The code:
package com.example.someproject;
public class MainC {
public static void main(String[] args) {
System.out.println("hey");
}
}
答案 0 :(得分:0)
这解决了我的问题-在Android Studio中,第一次运行main()方法时,右键单击main()方法的任意部分,然后选择“运行Coverage来运行'YourClass.main()'” 。下次运行main()时,只需单击运行按钮就可以完成此操作。
我也是Java的新手,所以我不确定为什么它会起作用,但是由于它对我有用,因此可能值得尝试。