PreferencePage自定义运行时空指针异常疑惑

PreferenceManager mgr = new PreferenceManager();
//------------------------------------------------
PreferenceNode portNode = new PreferenceNode("File","File Configure", null, null);
portNode.setPage(new OnePerferencePage(window));
//------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PreferenceNode portNode = new PreferenceNode("Port","Port Configure", null, OnePerferencePage.class.getName());
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

两段代码的区别,用上面段代码会报运行时空指针异常,为什么OnePerferencePage.class.getName()拿不到OnePerferencePage对象,
下面段代码运行正确。

mgr.addToRoot(portNode);
PreferenceDialog dialog = new PreferenceDialog(null, mgr);
dialog.open();

你可能感兴趣的:(Preference)