Eclipse Cloudio代码段中的ClassCastException

时间:2016-01-08 15:17:18

标签: java eclipse eclipse-plugin classcastexception eclipse-gef

我尝试使用Cloudio在Eclipse插件中生成wordclouds。要开始,我尝试让this snippet 工作。

我以1:1的比例复制/粘贴它,只将显示初始化更改为

final Display display = PlatformUI.getWorkbench().getDisplay();

因为我的插件也会创建一个显示器。 (我也尝试final Display display = Display.getCurrent();没有区别。)

现在wordcloud打开了,但它抛出了这个错误:

java.lang.ClassCastException: org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor cannot be cast to org.eclipse.gef4.cloudio.internal.ui.view.TagCloudView

来自代码段中的这一行:if (!display.readAndDispatch())

好吧,因为wordcloud仍然显示,错误对我来说不是太大的问题。但有一件事是,当我关闭wordcloud时,从我的插件启动的整个Eclipse IDE将被关闭。我找到this post here on SO关于这个问题,并尝试了解释那里的两个解决方案(重命名shell并更改/删除setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);),没有任何影响。所以我猜这个错误可能连接到ClassCastException?

编辑:我已尝试使用Cloudio网站上提供的其他代码段,结果完全相同。

编辑:这是我在开始时发布链接的原始片段(正如我所说,我已经取代了显示器的初始化):

   public static void main(String [] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display);
  TagCloud cloud = new TagCloud(shell, SWT.NONE);

  // Generate some dummy words - color, weight and fontdata must
  // always be defined.
  List<Word> words = new ArrayList<Word>();
  Word w = new Word("Hello");
  w.setColor(display.getSystemColor(SWT.COLOR_DARK_CYAN));
  w.weight = 1;
  w.setFontData(cloud.getFont().getFontData().clone());
  words.add(w);
  w = new Word("Cloudio");
  w.setColor(display.getSystemColor(SWT.COLOR_DARK_GREEN));
  w.setFontData(cloud.getFont().getFontData().clone());
  w.weight = 0.5;
  w.angle = -45;
  words.add(w);

  shell.setBounds(50,50, 300, 300);
  cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);

  // Assign the list of words to the cloud:
  cloud.setWords(words, null);
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) display.sleep();
  }
  display.dispose();
}

编辑:我已经解决了关闭shell导致关闭整个IDE的问题,方法是将shell设置为不可见来覆盖Close-event:

shell.addListener(SWT.Close, new Listener() {
        @Override
        public void handleEvent(Event event) {
            shell.setVisible(false);
        }
      });

修改:Here is everything the console outputs when I open the wordcloud.这几次:

!ENTRY org.eclipse.ui 4 4 2016-01-10 14:47:42.403
!MESSAGE Internal plug-in action delegate error on creation.
!STACK 0
java.lang.ClassCastException: org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor cannot be cast to org.eclipse.gef4.cloudio.internal.ui.view.TagCloudView
    at org.eclipse.gef4.cloudio.internal.ui.actions.AbstractTagCloudAction.init(AbstractTagCloudAction.java:43)
    at org.eclipse.ui.internal.WWinPluginAction.initDelegate(WWinPluginAction.java:187)
    at org.eclipse.ui.internal.PluginAction.createDelegate(PluginAction.java:125)
    at org.eclipse.ui.internal.WWinPluginAction.refreshActionList(WWinPluginAction.java:167)
    at org.eclipse.ui.plugin.AbstractUIPlugin$1.run(AbstractUIPlugin.java:495)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1488)

0 个答案:

没有答案