我有以下代码。
MessageDialog dialog = new MessageDialog(new Shell(), "title", null, "message", MessageDialog.QUESTION, choices, 0); // choices is an array
当我dialog.open()
时给予NPE。任何线索?
答案 0 :(得分:5)
你不能像这样创建一个shell。您需要从启动对话框的上下文中访问现有Shell。如果您有任何SWT控件的引用,则可以从那里访问shell。
答案 1 :(得分:2)
使用MessageDialog的常规方法是通过静态open *方法之一,例如MessageDialog.openInformation(...)
。但是你的问题可能与你传递的shell有关。
答案 2 :(得分:2)
在choices
中看起来某些值可能为空。