运行程序的主要功能

Gal*_*Gal 3 sdk android android-gradle-plugin

我正在尝试通过 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");
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 11

这个解决了我的问题 - 在 Android Studio 中,第一次运行 main() 方法时,右键单击 main() 方法的任何部分,然后选择“Run 'YourClass.main()' with Coverage”。下次运行 main() 时,您应该可以通过单击运行按钮来完成它。

我也是一个 Java 新手,所以我不确定为什么这有效,但因为它对我有用,所以可能值得一试。