2016-02-13 60 views
2

作为一名JAVA初学者,我尝试通过教程使用GRAL。我是约以下错误:关于来自GRAL安装的super()关键字和.properties文件的JAVA问题

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放在与上面源代码相同的目录中。这没有奏效。

回答

0

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

你的情况的问题是文件drawablewriters.properties不是超类构造函数可以找到它的地方。您应该查看AbstractIOFactory的文档以了解它如何解析属性文件名。

+0

好的,谢谢Jim。 – brb