當我第二次創建新的SWT應用程序窗口時,應用程序崩潰,出現SWTException: Widget is disposed
錯誤。怎麼了?SWTException:部件已配置
這裏是我的代碼:
摘要Controller.java
:
public abstract class Controller {
protected View view;
public Controller(View v) {
view = v;
}
protected void render() {
data();
view.setData(data);
view.render();
listeners();
if (display)
view.open();
}
protected void data() {}
protected void listeners() {}
}
AboutController.java
(represends新窗口):
public class AboutController extends Controller {
static AboutView view = new AboutView();
public AboutController() {
super(view);
super.render();
}
}
摘要View.java
:
public abstract class View {
protected Display display;
protected Shell shell;
protected int shellStyle = SWT.CLOSE | SWT.TITLE | SWT.MIN;
private void init() {
display = Display.getDefault();
shell = new Shell(shellStyle);
};
protected abstract void createContents();
public View() {
init();
}
public void render() {
createContents();
}
public void open() {
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
而且我認爲AboutView.java
public class AboutView extends View implements ApplicationConstants {
protected void createContents() {
shell.setSize(343, 131);
shell.setText("About");
Label authorImage = new Label(shell, SWT.NONE);
authorImage.setBounds(10, 10, 84, 84);
authorImage.setImage(SWTResourceManager.getImage(AboutView.class,
"/resources/author.jpg"));
}
}
當我嘗試創建新的應用程序窗口中,然後new AboutController()
發生Widget is disposed
錯誤。
你爲什麼不發佈異常堆棧跟蹤? – isnot2bad