为什么我的班级不被接受 [英] Why is my class not acceptable

查看:173
本文介绍了为什么我的班级不被接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用Java,我试图使用Intellij IDEA来探索Hello World。

This is my first forray into Java, and I am trying to get my head around "Hello World" using Intellij IDEA.

这不是语法我我遇到了麻烦,更多的是IDE本身。

It's not so much the syntax I am having trouble with, more the IDE itself.

首先,我已经下载并安装了IntelliJ IDEA,以及32位和64位版本的Java JDK 。 IDEA可以轻松找到我的Java JDK安装,并为我提供intellisense。我创建了一个名为 Test 的测试解决方案,以及一个 src 目录来放置我的源文件。我的解决方案资源管理器如下所示:

First of all, I have downloaded and installed IntelliJ IDEA, and both the 32 bit and 64 bit versions of the Java JDK. IDEA has no trouble finding my Java JDK install, and providing me with intellisense. I have created a test solution named Test, and a src directory to place my source files. My solution explorer looks like this:

我的Java类如下,它成功编译:

My Java class is below, it compiles successfully:

public class HelloWorld {

    static void main(String[] args){
        System.out.println("Hello World");
    }


}

我添加了Java JDK到我的计算机上的环境变量,我能够导航到已编译的类,并在命令行中运行它。它运行正常。

I have added the Java JDK to my environmental variables on my computer, and I am able to navigate to the compiled class, and run it in command line. It runs fine.

每当我尝试从IDEA内部运行该类时,出于调试目的,我的问题就出现了。当我点击运行时,它会要求我编辑我的环境变量。在出现的对话框中,我在默认值下选择应用程序,然后尝试选择 HelloWorld 作为我的主要课程。我收到一条错误,告诉我 HelloWorld 是不可接受的,如下所示:

My issue comes whenever I try and run the class from inside IDEA, for the purposes of debugging. When I click on Run, it asks me to edit my Environmental variables. In the dialogue box that appears, I select Application under Defaults, and try and select HelloWorld as my main class. I get an error telling me that HelloWorld is not acceptable, as shown below:

我的问题是,如何在IDEA中运行我的Java控制台应用程序为了调试的目的?我做错了什么?

My question is, how do I run my Java console application inside IDEA for the purpose of debugging? What am I doing wrong?

推荐答案

main 方法应该带 public 修饰符

public static void main(String[] args)

甚至更好

public static void main( final String[] args )

这篇关于为什么我的班级不被接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆