错误:找不到或加载主类ClassDemo [英] Error: Could not find or load main class ClassDemo

查看:265
本文介绍了错误:找不到或加载主类ClassDemo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在此成功编译 https://www.compilejava.net/ 但执行失败

The code below compiled successfully here https://www.compilejava.net/ but execution fails


错误:无法找到或加载主类ClassDemo

Error: Could not find or load main class ClassDemo

虽然它确实有一个主要切入点。为什么?

whereas it does have a main entry point. Why ?

package com.tutorialspoint;

import java.lang.reflect.*;

public class ClassDemo {

   public static void main(String[] args) {

     try {            
        ClassDemo c = new ClassDemo();
        Class cls = c.getClass();

        // returns the array of Field objects
        Field[] fields = cls.getDeclaredFields();
        for(int i = 0; i < fields.length; i++) {
           System.out.println("Field = " + fields[i].toString());
        }
     }
     catch(Exception e) {
        System.out.println(e.toString());
     }
   }

   public ClassDemo() {
      // no argument constructor
   }

   public ClassDemo(long l, int i) {
      this.l = l;
      this.i = i;
   }

   long l = 77688;
   int i = 3;
}


推荐答案

您需要删除包裹您使用在线编译器/执行程序时代码中的标识符(第一行)。

You need to remove the package identifier from your code (first line) since you are using an online compiler/executor.

希望这会有所帮助。

这篇关于错误:找不到或加载主类ClassDemo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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