我有一個類,由吉斯注入這個類的構造函數調用超級,與資源由class.getResource裝(..)如何注入資源與吉斯
@SuppressWarnings("serial")
public class CleanAction extends AbstractAction {
private final JTable table;
private final PowderTableModel tableModel;
@Inject
public CleanAction(@Named("data") JTable table, PowderTableModel tableModel) {
super("Clean", new ImageIcon(CleanAction.class.getResource("/icons/table.png")));
this.table = table;
this.tableModel = tableModel;
}
...
}
它工作在測試正常,但在guice初始化過程中,CleanAction.class.getResource(「icons/table.png」)的結果爲null,所以它失敗並返回NullPointerException。
有什麼方法可以注入資源嗎?
感謝的好膽量的項目,這似乎是罰款。 – 2010-09-13 08:04:52