我看过一篇关于Class.forName是否可以在这里返回null的帖子,每个人似乎认为它不能(或不会).但是,它使用以下代码为我返回null:
public void init() {
File binDriectory = new File("./bin/dft");
String[] files = binDriectory.list();
for (String file : files) {
if (file.endsWith(".class")) {
if (file.indexOf("DataReader") > 0) {
//strip off the ".class"
String className = file.substring(0, file.indexOf(".class"));
try {
//load the class
Class readerclass = Class.forName("dft." + className);
//get the file extension of the file type this class deals with
/* NullPointerException thrown here in call to getMthod() */
Method getExtensionMethod = readerClass.getMethod("getFileExtension", null);
String extension = (String) …Run Code Online (Sandbox Code Playgroud)