10 Replies Latest reply: Apr 6, 2010 6:58 PM by jschellSomeoneStoleMyAlias RSS

    please help with java.lang.NoSuchMethodError

    843798
      hello,

      what i currently have:

      i have 3 classes, each is compiled and wrapped inside an executable (.exe). they are A.exe, B.exe & C.exe.
      inside main() of A.java, i used Runtime().exec() to launch B.exe and C.exe (ex: Runtime().exec("A.exe arg")).
      both B.exe & C.exe spawn threads to do "stuff".

      what i'd like to have:

      inside main() of A.java, i'd like to be able to do: new B("test");
      i was able to compile (i had to add classpaths for B & C to the manifest file and to the script to compile A) but when
      i ran A.exe i got "java.lang.NoSuchMethodError" errors on class B.

      how do i rectify this?

      thanks
      kt
        • 1. Re: please help with java.lang.NoSuchMethodError
          791266
          anonimuds wrote:
          hello,

          what i currently have:

          i have 3 classes, each is compiled and wrapped inside an executable (.exe). they are A.exe, B.exe & C.exe.
          inside main() of A.java, i used Runtime().exec() to launch B.exe and C.exe (ex: Runtime().exec("A.exe arg")).
          both B.exe & C.exe spawn threads to do "stuff".
          Huh? Why? This sounds so very odd and strange. You are probably having a desing problem.

          >
          what i'd like to have:

          inside main() of A.java, i'd like to be able to do: new B("test");
          i was able to compile (i had to add classpaths for B & C to the manifest file and to the script to compile A) but when
          i ran A.exe i got "java.lang.NoSuchMethodError" errors on class B.

          how do i rectify this?
          What? NoSuchMethodError means that the class that you are invoking a method on is of another version than the one that you had on the classpath when you compiled, and the new class is missing a method that you had in the old version.
          • 2. Re: please help with java.lang.NoSuchMethodError
            843798
            i should mention that the 3 classes used to be standalone apps, with no references to each other.
            the errors are on methods of classes defined in project B (in which B.java contains main()).

            again, in main() of A.java, the only reference to B is "new B("test")" and the constructor calls
            code within project B. as i said, using exec() works, so i don't know what you mean by version this & that.

            thanks
            • 3. Re: please help with java.lang.NoSuchMethodError
              791266
              anonimuds wrote:
              i should mention that the 3 classes used to be standalone apps,
              Written in Java?
              with no references to each other.
              the errors are on methods of classes defined in project B (in which B.java contains main()).

              again, in main() of A.java, the only reference to B is "new B("test")" and the constructor calls
              Post the full stacktrace, but I would guess that you have two different java files named B.
              code within project B. as i said, using exec() works, so i don't know what you mean by version this & that.
              See above.
              • 4. Re: please help with java.lang.NoSuchMethodError
                843798
                B & C are written in java.
                it's not a design issue: i'm given B & C (say, as executable jars) and I can only instantiate B & C in my own A.java. a real world example of such a situation?
                suppose you have to write a screensaver that randomly selects a screensaver (from \system32) to run; in this case exec() is used to launch the selected screensaver.

                so, given that B & C are written in stone, how do i resolve the errors?

                thanks
                • 5. Re: please help with java.lang.NoSuchMethodError
                  843798
                  i suspect that you may be right that i may have naming collisions between A & B.
                  • 6. Re: please help with java.lang.NoSuchMethodError
                    843798
                    now i'm not sure
                    • 7. Re: please help with java.lang.NoSuchMethodError
                      791266
                      anonimuds wrote:
                      B & C are written in java.
                      it's not a design issue: i'm given B & C (say, as executable jars) and I can only instantiate B & C in my own A.java.
                      So, are you having B and C in jars or in exe files? It's a huge difference. Just compile your code against those jars in that case. You will probably get compilation errors.
                      a real world example of such a situation?
                      suppose you have to write a screensaver that randomly selects a screensaver (from \system32) to run; in this case exec() is used to launch the selected screensaver.

                      so, given that B & C are written in stone, how do i resolve the errors?
                      I still don't get your relation between Java files, xxe files and classes. I wouldn't have a B.java/B.class if I had B.exe.
                      • 8. Re: please help with java.lang.NoSuchMethodError
                        843798
                        ok, from java projects B & C i was able to produce 2 executable jars B.jar & C.jar (neither knows anything about project A nor about each other and both work).

                        in A.java: i have "import bpackage.B" and in main() i have "new B("test");"
                        in the script to compile project A: i have "-cp pathB\B.jar" and in the manifest i have "Class-Path: pathB\B.jar"
                        it compiled but when i ran A.jar i got:

                        Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: objInB.ObjectInB.<init>(Ljava/awt/Graphics;Ljava/awt/Image;Ljava/awt/Color;IILj
                        ava/lang/String;Z)V
                        at bpackage.B.methodToInstantiateObjectInB(Unknown Source)
                        ...etc...

                        thanks
                        • 9. Re: please help with java.lang.NoSuchMethodError
                          843798
                          errors resolved: i needed to include B's classes when creating A.jar; and since the 2 sets of classes are combined, they can't have the same package & class names (which i did have).

                          thanks.
                          • 10. Re: please help with java.lang.NoSuchMethodError
                            jschellSomeoneStoleMyAlias
                            anonimuds wrote:
                            B & C are written in java.
                            it's not a design issue: i'm given B & C (say, as executable jars) and I can only instantiate B & C in my own A.java. a real world example of such a situation?
                            suppose you have to write a screensaver that randomly selects a screensaver (from \system32) to run; in this case exec() is used to launch the selected screensaver.
                            Good example. So the way that works is that the executable, because it is an executable, runs in its own process. It doesn't run in the process that wraps it.

                            You on the other hand are not doing that.

                            If you want a plugin architecture then you use a interface that defines it as such. If you want to run an executable then you use Runtime.exec().
                            In more complex scenarios you might need to use a custom class loader to, for example, deal with packages that overlap.