简体   繁体   中英

Java can't find existing method in a class

I have jar archive build with Ant 1.9.1 When I launch class from it I get the following exception:

Caused by Java exception: java.lang.NoSuchMethodError: com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput.setChecked(Z)V
        at com.blablabla.kats.drivers.CheckBox.check(CheckBox.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.blablabla.kats.utils.Operation.doInvoke(Operation.java:142)
        at com.blablabla.kats.utils.Operation.invokeMethod(Operation.java:117)
        at com.blablabla.kats.model.handles.ElementOperationHandle.invokeOn(ElementOperationHandle.java:33)
        at com.blablabla.kats.model.statements.DirectAction.execute(DirectAction.java:45)
        at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
        at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
        at com.blablabla.kats.model.Procedure.call(Procedure.java:46)
        at com.blablabla.kats.model.statements.Invocation.execute(Invocation.java:48)
        at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
        at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
        at com.blablabla.kats.model.TestCase.execute(TestCase.java:41)
        at com.blablabla.kats.model.TestSuite.execute(TestSuite.java:45)
        at com.blablabla.kats.model.TestProgram.execute(TestProgram.java:40)
        at com.blablabla.kats.Main.main(Main.java:158)

When I compile "com.blablabla.kats.drivers.CheckBox" class by javac and replace corresponding file in jar all works fine. I use htmlunit 2.12

java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

corresponding Ant task:

<path id="classpath.libraries">
    <fileset dir="${basedir}/lib">
      <include name="*.jar"/>
    </fileset>
  </path>


     <target name="compile">
        <javac srcdir="${basedir}/src/java" destdir="classes"  debug="true" source="1.5" target="1.5">
          <classpath refid="classpath.libraries" />
        </javac>
      </target>

${basedir}/lib contains a lot of jars.
The main are kats.jar - my project, containing com.blablabla.kats.drivers.CheckBox
htmlunit-2.12.jar - where com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput.setChecked(Z) is.

Why it can happen?

The only difference that i see is, you are using 1.5 in ant script where as looking at the java version you are using java6 to run it. I am not sure if this may make a big difference as it should be backward compatible, but still give it a try. Change this version to 1.6 in ant build.xml

I found out that I didn't delete old compiled class. When I cleaned up compiled classes all worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM