简体   繁体   English

在 java 中运行主命令

[英]Running the main command in java

I started to learn Java 2 days ago.我2天前开始学习Java。 When I try to run this code:当我尝试运行此代码时:

public class Main {

public static void main(String[] args) {

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

The terminal says:终端说:

    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()'.

Altough, I tried to delete the尽管如此,我试图删除

build.gradle(:app)

this is what my gradle file looks like:这是我的 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'
}

But it did not worked.但它没有奏效。 Could you please me to solve this issue?你能请我解决这个问题吗?

running fine to me:对我来说运行良好:

public class Main{

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

output: output:

10

are you compiling it right?你编译对了吗?

It seems that your project is an android project.看来您的项目是 android 项目。 Thus the gradle errors.因此 gradle 错误。

if your aim is to learn java and not android, just changing your IDE to eclipse or Intellij would solve your problem如果您的目标是学习 java 而不是 android,只需将 IDE 更改为 Z6B7B655DD522FAA3F1024 即可解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM