美文网首页
Android studio 执行main方法报错

Android studio 执行main方法报错

作者: 马路牙子666 | 来源:发表于2021-03-18 20:12 被阅读0次

Android studio 执行main方法报错

运行 Java main 方法报错

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}
* Where:
Initialization script 'C:\xxx\Hello_main__.gradle' line: 21

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Hello.main()'.
   > SourceSet with name 'main' not found.

解决办法:
项目 .idea 文件夹中 gradle.xml 文件中 添加 <option name="delegatedBuild" value="false" /> ,添加完如下

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleMigrationSettings" migrationVersion="1" />
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="testRunner" value="PLATFORM" />
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="gradleJvm" value="1.8" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
            <option value="$PROJECT_DIR$/app" />
            <option value="$PROJECT_DIR$/hello" />
          </set>
        </option>
        <option name="delegatedBuild" value="false" />
      </GradleProjectSettings>
    </option>
  </component>
</project>

相关文章

网友评论

      本文标题:Android studio 执行main方法报错

      本文链接:https://www.haomeiwen.com/subject/nxbpcltx.html