【问题标题】:JFace and Assertion ClassNotFoundException in EclipseEclipse 中的 JFace 和断言 ClassNotFoundException
【发布时间】:2014-09-20 19:02:20
【问题描述】:

我正在浏览一本书中的示例,但我遇到了错误,我不知道究竟是什么导致了它以及如何解决它。

操作系统:Windows7 64bit,适用于 Java 开发人员的 Eclipse IDE,安装了 JFace 或更好地说是附加到项目的 jar,Eclipse 附带的默认 jar:

  • org.eclipse.jface_3.8.102.v20130123-162658.jar
  • org.eclipse.jface.databinding_1.6.0.v20120912-132807.jar
  • org.eclipse.jface.text_3.8.2.v20121126-164145.jar

这是应用程序代码:

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class TableLayoutExample {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);

        shell.setSize(500, 400);
        shell.setText("Table Example");
        shell.setLayout(new FillLayout());

        TableLayout layout = new TableLayout();
        layout.addColumnData(new ColumnWeightData(40, 80, true));
        layout.addColumnData(new ColumnWeightData(40, 80, true));
        layout.addColumnData(new ColumnWeightData(40, 80, true));
        Table table = new Table(shell, SWT.SINGLE);
        table.setLayout(layout);
        TableColumn column1 = new TableColumn(table, SWT.CENTER);
        TableColumn column2 = new TableColumn(table, SWT.CENTER);
        TableColumn column3 = new TableColumn(table, SWT.CENTER);
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(new String[] { "column 1", "column 2", "column 3" });
        item = new TableItem(table, SWT.NONE);
        item.setText(new String[] { "a", "b", "c" });

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

这是错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/Assert
    at org.eclipse.jface.viewers.ColumnWeightData.<init>(ColumnWeightData.java:70)
    at TableLayoutExample.main(TableLayoutExample.java:21)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.Assert
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more

有什么想法可能会出错吗?

【问题讨论】:

标签: java jface assert eclipse-juno


【解决方案1】:

来自Download eclipse-equinox-common-3.5.0.jar

Files contained in eclipse-equinox-common-3.5.0.jar: 

.api_description
META-INF/ECLIPSEF.RSA
META-INF/ECLIPSEF.SF
META-INF/MANIFEST.MF
META-INF/eclipse.inf

...

org.eclipse.core.runtime.Assert.class
org.eclipse.core.runtime.AssertionFailedException.class

看来您缺少最新版本的 eclipse-equinox-common.jar 或者它不在您的类路径中...

【讨论】:

  • 谢谢。缺少的文件是(在我的情况下)org.eclipse.equinox.common_3.6.100.v20120522-1841.jar,案例已解决。
猜你喜欢
  • 2011-04-01
  • 1970-01-01
  • 2011-07-27
  • 1970-01-01
  • 1970-01-01
  • 2013-03-08
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
相关资源
最近更新 更多