下面的代码在这里编译成功https://www.compilejava.net/但执行失败
Error: Could not find or load main class ClassDemo
而它确实有一个主要入口点。为什么?
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;
}
最佳答案
由于您使用的是在线编译器/执行器,因此需要从代码(第一行)中删除包标识符。
希望这有帮助。
关于java - 错误: Could not find or load main class ClassDemo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36402759/