gpt4 book ai didi

java - 在java中运行主命令

转载 作者:行者123 更新时间:2023-12-01 17:26:15 24 4
gpt4 key购买 nike

我2天前开始学习Java。当我尝试运行此代码时:

public class Main {

public static void main(String[] args) {

System.out.println(5*2);
}
}

终端显示:

    12:47:17 PM: Executing task 'Main.main()'...

Executing tasks: [Main.main()] in project C:\Users\Safakhan\AndroidStudioProjects\JavaBasics2


FAILURE: Build failed with an exception.

* Where:
Initialization script 'C:\Users\Safakhan\AppData\Local\Temp\Main_main__.gradle' line: 20

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Main.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.6.4/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 298ms
12:47:17 PM: Task execution finished 'Main.main()'.

尽管如此,我还是尝试删除

build.gradle(:app)

这就是我的 gradle 文件的样子:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}

但是没有成功。您能帮我解决这个问题吗?

最佳答案

对我来说运行良好:

public class Main{

public static void main(String []args){
System.out.println(5*2);
}
}

输出:

10

你编译对了吗?

关于java - 在java中运行主命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61205092/

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