我尝试启动的每个java程序都显示错误 [英] Every java program I try to start shows error

查看:591
本文介绍了我尝试启动的每个java程序都显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决,程序位于其路径中的国家符号。



我刚刚开始学习java,但我尝试启动的每个程序(甚至是我的例子)当然)显示错误。

 错误:无法找到或加载主类我尝试启动的程序的任何类名
C:\ Users \Mine \ AppData \ Local \ NetBeans \Cache \8.1 \executor-snippets\run.xml:53:Java返回:1
BUILD FAILED(总时间:0秒)

编辑:



代码示例,但适用于任何代码。

  public class Hello {

static void hello(){
System.out.println(Hello,World!);

}

public static void main(String [] args){
hello();

}
}


解决方案

此错误意味着当Netbeans调用JVM时,JVM无法找到Netbeans告诉它运行的类的类文件。在Netbeans中创建项目时,将为您配置



然后点击运行并检查名称主要班级中的课程:





注意我的例如,该类称为tests.Test。这意味着测试中的课程测试。在您的问题中,您的类Hello顶部没有包声明(尽管您可能选择不复制此声明)。如果你没有包(并且你真的应该使用包,即使对于像你好,世界!这样的琐碎程序,只是为了习惯这样做,如果没有别的话),主类条目应该只是类名。



因此,您需要将类移动到此参数中指定的包中,或者更改此参数以匹配主类的完全限定名称


SOLVED, Program was in location with national symbol in it's path.

I just started studying java, but every program i try to start (even example ones from my course) shows an error.

Error: Could not find or load main class "Any class name of program I try start"
C:\Users\Mine\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53:           Java returned: 1
BUILD FAILED (total time: 0 seconds)

edit:

example of code, but happens to any code.

public class Hello {

    static void hello(){
        System.out.println("Hello, World!");

    }

    public static void main(String[] args) {
        hello();

    }    
}

解决方案

This error means that when Netbeans is invoking the JVM, the JVM cannot find the class file for the class Netbeans is telling it to run. When you create a project in Netbeans, the classpath will be configured for you by the IDE, so you shouldn't normally see this error unless you have deleted the auto-generated main class and made a new one from scratch in the wrong place.

So the first thing to do is check what class Netbeans is using as the main class:

Right-click on the project name in the Projects tab and click on "Properties"

Then click on "Run" and check the name of the class in "Main Class":

Note in my example the class is called "tests.Test". This means the class Test in the package "tests". In your question, your class "Hello" doesn't have a package declaration at the top (although you may have chosen not to copy this). If you have no package (and you really should be using packages, even for trivial programs like "Hello, World!", just to get used to doing so, if nothing else), the "Main Class" entry should just be the class name.

So you need to either move your class into the package specified in this parameter, or change this parameter to match the fully qualified name of your main class

这篇关于我尝试启动的每个java程序都显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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