2016-12-06 92 views
0

我使用Eclipse RAP来实现Web应用程序。下面的代码选择listener的执行过程中抛出一个NullPointerExceptionEclipse RAP Dialog :: open()抛出NullPointerException

Link link = new Link(composite_2, SWT.NONE); 
link.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); 
link.setText("<a>Dokument erfassen</a>"); 
link.addSelectionListener(new SelectionAdapter() { 
    @Override 
    public void widgetSelected(SelectionEvent arg0) { 

     TestDialog dia = new TestDialog(getShell(), 
        SWT.APPLICATION_MODAL); 
     dia.open(new DialogCallback() { 
      public void dialogClosed(int returnCode) { 
       System.out.println("Stored file: "); 
      } 
     }); 
    } 
}) 

enter image description here

类TestDialog貌似的代码如下:

public class TestDialog extends Dialog { 
    private static final long serialVersionUID = 1L; 

    public TestDialog(Shell parent) { 
     super(parent); 
    } 

    public TestDialog(Shell parent, int style) { 
     super(parent,style); 
    } 
} 

如果我使用MessageBox类代替一流的TestDialog,一切工作正常。

+0

我看你是新来的SO 如果你觉得一个答案的问题解决了,请把它标记为点击绿色的勾号即可“接受”。这有助于将重点放在仍然没有答案的旧帖子上。 –

回答

0

Dialog.open方法的RAP 3.1实现使用shell.open(),但我找不到变量shell实际设置为值的位置?这不应该是“父母”吗?

public void open(final DialogCallback dialogCallback) { 
    prepareOpen(); 
    returnCode = SWT.CANCEL; 
    shell.open(); 
    shell.addShellListener(new ShellAdapter() { 
     @Override 
     public void shellClosed(ShellEvent event) { 
     if(dialogCallback != null) { 
      dialogCallback.dialogClosed(returnCode); 
     } 
     } 
    }); 
    } 
0

你实现Dialog需要重写prepareOpen()在默认情况下不执行任何操作。

prepareOpen()返回后,代表该对话框的Shell应创建并分配到shell字段。

例如:

shell = new Shell(parent, SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); 
shell.setText(getText()); 
// create controls in shell 

一个更完整的示例,请参阅FontDialoghttps://github.com/eclipse/rap/blob/master/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/FontDialog.java

相关问题