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
8 Respostas
+ 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()
+ 1
Isn't that because your getExtra() is private?
+ 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.
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
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
0
It's public. I forgot to add that line when copying over
0
You're gonna kill me, ha. That was supposed to be "private e" for the variable that is returned.