我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/