0

stackoverflowerror - help would be awesome

The following code throws a stack overflow error. I enter 'E', then it goes to the second add method ( these methods are overloaded ). Then I enter, for example, "Amazon" "AMZN" "A" "237.33" "10" (for the userStockName, userTicker, userExtended, userPrice, and userNumber). Once I click enter after the userNumber ( last value ) is entered, it throws a stackoverflowerror.( the stock is stored in the array arrObj[count] = E ). code: https://code.sololearn.com/cVTMLQDem3kF/#java https://code.sololearn.com/cLg1JBXL38cJ/#java

6th Apr 2020, 1:34 AM
Fare Jare
Fare Jare - avatar
8 odpowiedzi
+ 1
StackOverflow occurs when there is an infinite loop or infinite recursion. You overloaded methods should take different parameter types, regardless of the parameter names. Link to method overloading lesson https://www.sololearn.com/learn/Java/2165/ A simple solution will be, give the two functions a different name: add1() and add2()
6th Apr 2020, 1:44 AM
Gordon
Gordon - avatar
+ 1
Isn't that because your getExtra() is private?
6th Apr 2020, 2:25 AM
Gordon
Gordon - avatar
+ 1
I see your latest change. Instead of adding public at line 6 where you call the getExtra() You should replace the private keyword with public keyword at line 21 where getExtra() is defined.
6th Apr 2020, 2:32 AM
Gordon
Gordon - avatar
0
- Gordan I am required to use overloaded methods. ( i tested and changed the name, I still have the same error ). Also the link leads to a page not found
6th Apr 2020, 1:50 AM
Fare Jare
Fare Jare - avatar
0
I figured out that if I take out the Etf etf = new Etf(); line out of my Stock class, It runs fine. But I eventually have to use an object to access a get method that is inside of the Etf class, and now I cannot access it because the object is not created. It tells me to create the getExtra method inside of my Stock class, but it has to be made inside of my Etf class. I added another link to my main message thread to show the stock, etf, and mf classes
6th Apr 2020, 2:14 AM
Fare Jare
Fare Jare - avatar
0
It's public. I forgot to add that line when copying over
6th Apr 2020, 2:28 AM
Fare Jare
Fare Jare - avatar
0
You're gonna kill me, ha. That was supposed to be "private e" for the variable that is returned.
6th Apr 2020, 2:46 AM
Fare Jare
Fare Jare - avatar