小编Tyl*_*ler的帖子

Class.forName返回null

我看过一篇关于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)

java classloader

3
推荐指数
1
解决办法
3368
查看次数

标签 统计

classloader ×1

java ×1