Android Studio拒绝运行main() [英] Android Studio refuses to run main()

查看:327
本文介绍了Android Studio拒绝运行main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

复制步骤:

  1. 在Android Studio中启动一个新项目(具有最新更新);
  2. 制作一个新类,并像往常一样添加main();
  3. 右键单击类以运行main()作为测试.

package test;

public class Test {
    public static void main(String[] args) {
    }
}

通常我希望我可以 System.out.printLn("H​​ello 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.

推荐答案

快速修复::您可以使用覆盖运行" 来运行.请参见下面的图片.

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

永久解决方案::添加< option name ="delegatedBuild"值=假"/>

在路径 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆