桌面应用程序

时间:2016-04-26 06:26:07

标签: java swing runtime-error classpath noclassdeffounderror

我在Java Swing中创建了一个表单,并希望使用API​​验证它们。 我已经包含了验证API,但是当我想运行这个类时,会出现如下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openide/util/Lookup
    at org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory.getDefault(SwingComponentDecorationFactory.java:154)
    at org.netbeans.validation.api.ui.swing.SwingValidationGroup.<init>(SwingValidationGroup.java:82)
    at org.netbeans.validation.api.ui.swing.SwingValidationGroup.create(SwingValidationGroup.java:87)
    at org.netbeans.validation.api.ui.swing.ValidationPanel.<init>(ValidationPanel.java:95)
    at org.netbeans.validation.api.ui.swing.ValidationPanel.<init>(ValidationPanel.java:109)
    at Main.main(Main.java:23)
Caused by: java.lang.ClassNotFoundException: org.openide.util.Lookup
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

我包含的jar文件是(ValidationAPI.jar) 所以我不知道是什么问题。

有谁知道如何解决这个问题?

这是我的代码:

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.netbeans.validation.api.builtin.stringvalidation.StringValidators;
import org.netbeans.validation.api.ui.ValidationGroup;
import org.netbeans.validation.api.ui.swing.ValidationPanel;

public class Main{

@SuppressWarnings("unchecked")
public static void main(String[] args) {

    JPanel inner = new JPanel();
    JLabel lbl = new JLabel("Enter a URL");
    JTextField f = new JTextField();
    f.setColumns(40);
    f.setName("URL");
    inner.add(lbl);
    inner.add(f);


   ValidationPanel panel = new ValidationPanel();
    panel.setInnerComponent(inner);
    ValidationGroup group = panel.getValidationGroup();
//    
    group.add(f, StringValidators.REQUIRE_NON_EMPTY_STRING,
            StringValidators.NO_WHITESPACE);

    if (panel.showOkCancelDialog("URL")) {

      System.out.println("User clicked OK.  URL is " + f.getText());
     System.exit(0);

    }
    else {
      System.err.println("User clicked cancel.");
      System.exit(1);
    }
  }
}

0 个答案:

没有答案