有关GRAL安装中的super()关键字和.properties文件的JAVA问题

时间:2016-02-13 04:27:01

标签: java properties runtime super

作为一名JAVA初学者,我尝试通过教程使用GRAL。我发现了以下错误:

java.lang.RuntimeException: java.io.IOException: Property file not found: drawablewriters.properties

此运行时错误来自以下未更改的GRAL源代码行:

public final class DrawableWriterFactory extends AbstractIOFactory<DrawableWriter> {
 /** Singleton instance. */
 private static DrawableWriterFactory instance;

 /**
  * Constructor that initializes the factory.
  * @throws IOException if the properties file could not be found.
  */
 private DrawableWriterFactory() throws IOException {
  super("drawablewriters.properties"); //$NON-NLS-1$
 }

 /**
  * Returns an instance of this DrawableWriterFactory.
  * @return Instance.
  */
 public static DrawableWriterFactory getInstance() {
  if (instance == null) {
   try {
    instance = new DrawableWriterFactory();
   } catch (IOException e) {
    throw new RuntimeException(e);
   }
  }
  return instance;
}

上面的类是另一个类中的引用,该类引用了最初运行的代码。

在阅读关键字super之后,在构造函数中使用时,似乎super绝不会将.properties文件作为参数。在这种情况下,它如何使用.properties文件?

我注意到在以下question中,通常使用新的InputStream来提取.properties文件的内容。这是以某种方式完成的超级?

另外,我只是尝试将drawablewriters.properties放在与上面源代码相同的目录中。这没有用。

1 个答案:

答案 0 :(得分:0)

语法super("drawablewriters.properties");仅仅是对这个类的超类的构造函数的调用。它可以包含一个超类'构造函数所采用的任何参数。在这种情况下,它正在调用AbstractIOFactory<DrawableWriter>

的构造函数

您的案例中的问题是文件drawablewriters.properties不是超类构造函数可以找到它的位置。您应该查看AbstractIOFactory的文档,了解它如何解析属性文件名。

相关问题