本人初学Java,这个问题已经困扰了我很长时间
新建了一个简单的Java工程里面就包含两个类,目的是点击主窗口的按钮后弹出一个jFace对话框,结果点击按钮后总是报如下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IStatus
at com.jack.IpEditor.TestIpEditor$1.widgetSelected(TestIpEditor.java:36)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at com.jack.IpEditor.TestIpEditor.main(TestIpEditor.java:47)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IStatus
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)
... 7 more
很困惑,试了各种办法都不行,源代码如下,敢情大虾看看问题在哪里,不胜感激
package com.jack.IpEditor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class TestIPDialog extends Dialog {
public TestIPDialog(Shell shell)
{
super(shell);
}
@Override
protected Control createContents(Composite parent)
{
Composite container = new Composite(parent,SWT.NONE);
container.setLayout(new GridLayout());
Label lb = new Label(container,SWT.NONE);
lb.setText("IpEditor:");
return container;
}
}
package com.jack.IpEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestIpEditor {
private static Shell curShell = null;
public static void main(String[] args)
{
Display display = new Display();
curShell = new Shell(display);
Button btn = new Button(curShell,SWT.PUSH);
btn.setText("按我");
btn.addSelectionListener(new SelectionListener()
{
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
com.jack.IpEditor.TestIPDialog ipDlg = new com.jack.IpEditor.TestIPDialog(curShell);
ipDlg.open();
}
});
btn.pack();
curShell.pack();
curShell.open();
while (!curShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
------解决方案--------------------
应该是路径设置的问题吧?
------解决方案--------------------
需要:
org.eclipse.jface_3.6.2.M20110210-1200.jar org.eclipse.jface.databinding_1.4.0.I20100601-0800.jar
org.eclipse.core.commands_3.6.0.I20100512-1500.jar org.eclipse.jface.text_3.6.1.r361_v20100825-0800.jar
org.eclipse.equinox.common_3.6.0.v20100503.jar org.eclipse.swt.gtk.linux.x86_3.6.2.v3659b.jar