gpt4 book ai didi

java - Android Studio 拒绝运行 main()

转载 作者:行者123 更新时间:2023-12-01 17:43:57 25 4
gpt4 key购买 nike

重现步骤:

  1. 在 Android Studio 中启动一个新项目(使用最新更新);
  2. 像往常一样创建一个新类并添加 main() ;
  3. 右键单击类以运行 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 还算陌生,不知道这些东西想告诉我什么。我已经用谷歌搜索过,但我发现的最接近的是隐藏此错误的方法(假设代码仍在编译)。我至少需要这段代码才能编译。

最佳答案

Quick Fix : You can run using Run with Coverage.. See Image Below.

J

Permanent Solution: Add <option name="delegatedBuild" value="false" /> and sync project.

内部文件gradle.xml在路径E:\Project\.idea\gradle.xml下。请参见下图。

enter image description here

关于java - Android Studio 拒绝运行 main(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57734823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com