0

別のクラスからメソッドを呼び出すクラスがあります。Ubuntu 13.04 でコンパイルして実行したところ、問題なく動作しました。OSX 10.8.4 では、次の出力が得られます。

スレッド「メイン」での例外 java.lang.NoSuchMethodError: ComplexTester.main(ComplexTester.java:11) での Complex.equals(LComplex;)Z

Eclipse、Netbeans、ターミナルで実行してみましたが、同じ出力が得られました。どんな助けでも大歓迎です。

複雑

public class Complex {

    private double real;
    private double imaginary;

    /**
     * 
     * @param real the real part of the Complex number
     * @param imaginary the imaginary part of the Complex number
     */
    public Complex(double newReal,double newImaginary){
        real=newReal;
        imaginary=newImaginary;
    }

    /**
     * 
     * @return the real part of the Complex number
     */
    public double getReal(){
        return real;
    }


    /**
     * 
     * @return the imaginary part of the complex number
     */
    public double getImaginary(){
        return imaginary;
    }

    /**
     * gives real a new value
     * @param newReal the new value of real
     */
    public void setReal(double newReal){
        real=newReal;
    }

    /**
     * gives imaginary a new value
     * @param newImaginary the new value of Imaginary
     */
    public void setImaginary(double newImaginary){
        imaginary=newImaginary;
    }


    /**
     * 
     * @param x the new Complex object whose instance variables must be added to the old one
     * @return a new Complex object that is a combination of the parameters of both Complex objects
     */
    public Complex add(Complex x){
        Complex result=new Complex(x.getReal()+real,x.getImaginary()+imaginary);
        return result;
    }


    /**
     * 
     * @param other the Complex object being compared
     * @return true if both Complex objects have the same imaginary and real parts
     */
    public boolean equals(Complex other){
        return other.getImaginary()==imaginary && other.getReal()==real;
    }


}

ComplexTester

public class ComplexTester {

    public static void main(String[] args){
        Complex x=new Complex(23.2,33.1);
        Complex y=new Complex(23.2,33.1);

        //test the equals method
        System.out.println(x.equals(y));
        System.out.println("Expected: True");

        //test the setImaginary() and setReal() methods
        x.setImaginary(2);
        x.setReal(5);

        //test the getImaginary() and getReal() methods
        System.out.println(x.getImaginary());
        System.out.println("Expected: 2");

        System.out.println(x.getReal());
        System.out.println("Expected: 5");

        //test the equals method again
        System.out.println(x.equals(y));
        System.out.println("Expected: False");

        //test the add method
        Complex added=x.add(y);
        System.out.println(added.getReal());
        System.out.println("Expected: 28.2");

        System.out.println(added.getImaginary());
        System.out.println("Expected: 35.1");



    }
}
4

2 に答える 2