私のメインメソッドで別のクラスのメソッドを呼び出そうとしているとき、そのタイトルに記述されているエラーを見つけようとしています。エラーは、私のクラスTestCalculatorの3行目を指しています。ここでは、コードは次のとおりです。"スレッド内の例外" main "java.lang.StackOverflowError"エラー?
TestCalculatorクラス
public class TestCalculator {
Double x;
TestCalculator c = new TestCalculator();
String string = "b";
Double doubleObject = 1.0;
double doublePrimitive = 2;
/*
* Chops up input on ' ' then decides whether to add or multiply.
* If the string does not contain a valid format returns null.
*/
public Double x(String x){
x("12 [ 3");
return new Double(0);
}
public void testParsing() {
if (c.x(doubleObject) == 17) {
System.out.println("Adding Success");}
else {
System.out.println("Adding Fail");
}
if (c.x(doublePrimitive) == 60) {
System.out.println("Multiplying Success");}
else {
System.out.println("Multiplying Fail");
}
if (c.x(string) == null) {
System.out.println("Valid operator Success");}
else {
System.out.println("Valid operator Fail");
}
}
/*
* Adds the parameter x to the instance variable x and returns the answer as a Double.
*/
public Double x(Double x){
System.out.println("== Adding ==");
x("12 + 5");
return new Double(0);
}
/*
* Multiplies the parameter x by instance variable x and return the value as a Double.
*/
public Double x(double x){
System.out.println("== Multiplying ==");
x("12 x 5");
return new Double(0);
}
}
メインクラス
public class Main {
public static void main(String[] args) {
TestCalculator call = new TestCalculator();
call.testParsing();
}
}
私はこのエラーが発生している理由として、あまりにもわかりません。誰かがこのエラーが何であるのか、なぜそれが起こっているのか理解するのを助けることができれば、それは自分自身と将来この問題を遭遇する可能性のある他の誰もが高く評価します。ありがとう。
あなたは何度も何を期待していますか? – Li357
私は、各メソッドに値を代入し、そのメソッドをmainメソッドで呼び出す方法を混同しています。すべてのメソッドが同じ名前を持つので、これはそれらのメソッドを区別する方法を私に混乱させます。 – user7128699
どういう意味ですか? – Li357