简体   繁体   English

无法加载主类Netbeans

[英]could not load main class netbeans

public class Sequence {

    public static void main(String[] args) {
        int limit=20;
        int sum=0;
        int a=0;
        int b=1;

        while(sum<limit)
        {
            sum=a+b;
            a=b;
            b=sum;
        }
    }
}

My Netbeans was working fine when I was using jdk 1.8.0.65 earlier but due do some reason I lost my data, I installed jdk 1.8.0.73 then and now my every program on Netbeans shows this error: 当我较早使用jdk 1.8.0.65时,我的Netbeans运行良好,但是由于某种原因我丢失了数据,因此我安装了jdk 1.8.0.73,现在,我在Netbeans上的每个程序都显示此错误:

run: Error: Could not find or load main class sequence.Sequence C:\\Users\\owais\\AppData\\Local\\NetBeans\\Cache\\8.1\\executor-snippets\\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds) 运行:错误:无法找到或加载主类序列。序列C:\\ Users \\ owais \\ AppData \\ Local \\ NetBeans \\ Cache \\ 8.1 \\ executor-snippets \\ run.xml:53:Java返回:1失败(总时间:0秒)

I googled the problem and updated the netbeans_jdk path in netbeans.config file but still it does not work. 我用谷歌搜索了问题,并更新了netbeans.config文件中的netbeans_jdk路径,但仍然无法正常工作。 I am new to programming I would really appreciate some help. 我是编程新手,我将非常感谢您的帮助。

Actuall, when you click the "Run" button on top of the netbeans window, it only run the application's main class . 实际上,当您单击netbeans窗口顶部的“运行”按钮时,它仅运行应用程序的主类。 but this Sequence class is not the main class of the project most probably. 但是此Sequence类很可能不是项目的主要类。 for this case to run this class you have to right click on Sequence class editor and select Run or Run as menu. 对于这种情况,要运行此类,您必须右键单击Sequence类编辑器,然后选择Run或Run as菜单。 Then this class will be executed on separate console, I hope this will work .. 然后,该类将在单独的控制台上执行,我希望这可以工作..

I have been a victim of this problem, but the project I was working on was a bit large and I happen to use multiple Jpanel under one JFrame to develop the project so the code was over 15,000 lines of codes. 我一直是这个问题的受害者,但是我正在从事的项目有点大,我碰巧在一个JFrame下使用多个Jpanel来开发该项目,因此代码超过了15,000行代码。 So this seem to happen when I build the project, the code were scanned but because of the long code under the main class, it fail to reach the end of the code and raise the fail to load the main class. 因此,这似乎在我构建项目,扫描代码时发生,但是由于主类下的代码太长,因此无法到达代码的末尾并导致无法加载主类。 This is how I solve the problem using the Netbeans IDE: 这就是我使用Netbeans IDE解决问题的方法:

  1. Remove unnecessary components and codes to reduce the code size. 删除不必要的组件和代码以减小代码大小。
  2. Right Click on the project name, then click refactor and rename the project name. 右键单击项目名称,然后单击“重构”并重命名项目名称。
  3. Also rename both the classes and jframes in the project. 还重命名项目中的类和jframe。
  4. Click Run Then Click Clean and build project. 单击运行,然后单击清理并生成项目。
  1. remove netbeans cache (help -> about) 删除netbeans缓存(帮助->关于)
  2. run netbeans as administrator 以管理员身份运行netbeans

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

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