public Lab7(File file) {
List<Item> items = null;
try {
items = InventoryReader.read(file);
} catch (ApplicationException e) {
LOG.error(e.getMessage());
return;
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, use the default.
}
try {
MainFrame frame = new MainFrame(items); // THIS IS WHERE I HAVE TROUBLE
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
背景:我将 MainFrame 的构造函数设置为接受一个列表。如何在我的应用程序的 main() 中执行此操作?
我得到错误:
无法引用以不同方法定义的内部类中的非最终变量“项目”
错误在于 MainFrame frame = new MainFrame(items)
我似乎无法将 MainFrame 类传递给 items 变量...这是为什么呢?
如何将此变量传递到 MainFrame 框架中?