0

I'm trying to add a call into a private static inner class which calls another class's static method.

So for example:

 public class A {
    public static boolean isNumber(){...};
 }

 public class B {
    private static class C {
        static boolean isNumber() {
             return A.isNumber();
          }
      }
  }

I'm not all too familiar with static inner classes and how they work, but when I try to do this I keep getting a NoClassDefFoundError for class A.

Could not initialize class A

java.lang.NoClassDefFoundError: Could not initialize class A

Is this behavior expected when making a call to another static method from a inner static class?

Kevin
  • 3,209
  • 9
  • 39
  • 53
  • 1
    Not. It is a classpath issue or a missing compiled class. – davidxxx Jan 17 '18 at 19:56
  • [Why am I getting a NoClassDefFoundError in Java?](https://stackoverflow.com/q/34413) – Pshemo Jan 17 '18 at 19:57
  • From what I've read, this error can also be caused by static initialization exceptions though. The reason I'm not sure it's a missing compiled class or classpath issue is because all other places where this missing class (in my example, class A) is used does not raise any issues. – Kevin Jan 17 '18 at 20:03
  • It is indeed possible but to think of it as a possibility you should provide the real code. `NoClassDefFoundError` is an exception not a compilation error. And your code has no executable class, that is, a class with a `main(String args[])` method. – davidxxx Jan 17 '18 at 20:15
  • Hmmm. Good to know that that's not the issue at least, thanks! In the real code, the problem originates from a junit test being run which through a series of calls eventually gets to the static method call resulting in this error. The reason I did not post the real code is because it would be a lot of code to paste, and I just wanted to validate that the issue isn't due to inner static classes (which I'm not very familiar with) – Kevin Jan 17 '18 at 21:05

0 Answers0