简体   繁体   English

我是 Java 的初学者,我有一条关于 .gradle 和带有 main 的 Soursets 的错误消息。 我怎么解决这个问题?

[英]I'm Beginner to Java, I have a error message with .gradle and Soursets with main. How can I solve this problem?

I'm beginner in Java and Android-Studio.我是 Java 和 Android-Studio 的初学者。 When trying to complete the first step, I came across a big problem.在尝试完成第一步时,我遇到了一个大问题。

When I typed my first Java code in Android Studio and I ran the code I received this error message...当我在 Android Studio 中键入我的第一个 Java 代码并运行该代码时,我收到了此错误消息...

FAILURE: Build failed with an exception. FAILURE:构建失败,出现异常。

  • Where: Initialization script 'C:\\Users\\forma\\AppData\\Local\\Temp\\asdb_main__.gradle' line: 20其中:初始化脚本 'C:\\Users\\forma\\AppData\\Local\\Temp\\asdb_main__.gradle' 行:20

  • What went wrong: A problem occurred configuring project ':app'.出了什么问题:配置项目“:app”时出现问题。

    Could not create task ':app:asdb.main()'.无法创建任务 ':app:asdb.main()'。

    > SourceSet with name 'main' not found. > 未找到名为“main”的 SourceSet。

So, I looked for the .gradle file, but I don't know what the problem is.所以,我寻找 .gradle 文件,但我不知道问题是什么。

How can I solve this problem?我怎么解决这个问题?

I ran this code but I got the error message.我运行了这段代码,但收到了错误消息。

package com.example.myapplication;

public class asdb {
    public static void main(String[] args) {
        int a;
        a=10;
        System.out.println(a);
    }
}

and this is .gralde code including line 20.这是 .gralde 代码,包括第 20 行。

def gradlePath = ':app'
def runAppTaskName = 'asdb.main()'
def mainClass = 'com.example.myapplication.asdb'
def javaExePath = 'C:/Program Files/Android/Android Studio/jre/bin/java.exe'
def _workingDir = 'C:/Users/forma/Desktop/practice/java2'

def sourceSetName = 'main'
def javaModuleName = null



allprojects {
  afterEvaluate { project ->
    if(project.path == gradlePath && project?.convention?.findPlugin(JavaPluginConvention)) {
      project.tasks.create(name: runAppTaskName, overwrite: true, type: JavaExec) {
        if (javaExePath) executable = javaExePath
        classpath = project.sourceSets[sourceSetName].runtimeClasspath
        main = mainClass

I am assuming you mean the build.gradle in this answer我假设你的意思是这个答案中的 build.gradle

have a build.gradle in the root as follows:在根目录中有一个 build.gradle 如下:

plugins {
    id 'java'
}

group 'x'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

and a 'settings.gradle' defining your root project name和定义根项目名称的“settings.gradle”

essentially let your IDE do all the initalising of the gradle files基本上让您的 IDE 完成所有 gradle 文件的初始化

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

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