2

我试图使用由静态嵌套类组成的工具类的常见功能。这些静态嵌套类实行的是命令式的界面:静态嵌套类访问抛出NoClassDefFoundError

public interface BooleanFunction{ 
    public boolean execute(); 
} 

类控股实现此接口这些常用的类是:

public class ExBooleans { 

    public static class isComponentOpen implements BooleanFunction { 

     private int widgetId; 
     private int componentId; 

     public isComponentOpen(int widgetId, int componentId) { 
      this.widgetId = widgetId; 
      this.componentId = componentId; 
     } 

     @Override 
     public boolean execute() { 
      return Widgets.getComponent(this.widgetId, this.componentId) != null; 
     } 
    } 

这意味着被称为像这样:

ExUtilities.makeCondition(new ExBooleans.isComponentOpen(RANGE_WIDGET_ID, RANGE_COOK_COMPONENT_ID), 1000) 

其中makeCondition接受BooleanFunction

public static boolean makeCondition (final BooleanFunction booleanFunction, int timeout){ 
    return Utilities.waitFor(new Condition() { 
     @Override 
     public boolean validate() { 
      return booleanFunction.execute(); 
     } 
    }, timeout); 
} 

这是为了提供更清晰易读的代码而提供的Utilities.waitFor(Condition c, int timeout)函数的封装。

然而,当我打电话makeCondition传入ExBooleans.isComponentOpen我收到运行时错误:

Unhandled exception in thread ~threadnumber~: java.lang.NoClassDefFoundError: api/ExBooleans$isComponentOpen 

从上面包含通话线路:

ExUtilities.makeCondition(new ExBooleans.isComponentOpen(RANGE_WIDGET_ID, RANGE_COOK_COMPONENT_ID), 1000) 

解决这个任何帮助将是不胜感激!

+0

你是怎么执行这个的?使用cmd行还是IDE? – ajduke 2013-03-13 04:40:40

+0

对我来说看起来不错,你确定类路径中存在这个类 – 2013-03-13 04:41:48

+0

一个封闭的源客户端,我无法从cmd行或IDE运行。编译脚本并在我无法控制的客户端运行。 – forTruce 2013-03-13 04:42:27

回答

0

我能解决这个问题通过拉interfacemakeCondition方法到一个单独的类,里面这两个和效用实现isComponentOpen,等有了这些都嵌套在一个班,我不再收到错误,并代码可能会更有意义地组合在一起。

我仍然不确定错误来自哪里。

+0

你能接受你自己的答案吗? – fglez 2013-03-14 11:38:24