【问题标题】:Running the main command in java在java中运行主命令
【发布时间】:2020-04-14 10:01:44
【问题描述】:

我 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'
}

但它没有奏效。你能请我解决这个问题吗?

【问题讨论】:

    标签: java eclipse gradle intellij-idea


    【解决方案1】:

    对我来说运行良好:

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

    输出:

    10
    

    你编译对了吗?

    【讨论】:

    • 感谢您的评论。你能分享你在 build.gradle(:app) 中的依赖类吗
    • 是的。我试图了解我在哪里犯了错误
    【解决方案2】:

    您的项目似乎是一个 android 项目。因此 gradle 错误。

    如果您的目标是学习 java 而不是 android,只需将 IDE 更改为 eclipse 或 Intellij 即可解决您的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 2012-08-19
      • 2012-07-03
      • 1970-01-01
      相关资源
      最近更新 更多