Forums Register Login

NullPointerException

+Pie Number of slices to send: Send
Some days ago, i saw a nice example of calculator on these pages, after I imported on Eclipse I understood, that what i needed was a nice tutorial to understand it better, so I found one really cool,
I would like to fix the NPE, but just I am not able.



and this is the calculator, I started to modify a bit to play with the code, thanks.
1
+Pie Number of slices to send: Send
Note that the stack trace of the exception tells you that the NullPointerException happens in line 81 of Calculator.java, in the constructor of class Calculator ("Calculator.<init>" means the constructor of Calculator).

The line numbers in the code you posted are not exactly the same as they are in your actual source code file, so it's hard to see which line exactly is line 81.

Lookup line 81 in Calculator.java. Something in that line is null, and you are most likely trying to call a method on that thing that is null.
1
+Pie Number of slices to send: Send
 

Giovanni Montano wrote:
I would like to fix the NPE, but just I am not able.




The stack trace is saying that in the constructor of the the Calculator class, located around line 81, is some code that is causing an NPE. You need to located that line of code, and you need to check the components of that line to hopefully find out what is null.

Having said that, it is also saying that the constructor is being called from the main method, and that call is near line 100. Unfortunately, the main() method is nowhere near line 100. So, the code that you are showing, and the stacktrace for the error doesn't seem to match. Perhaps, you should recompile everything, and run the code again.

Henry
+Pie Number of slices to send: Send
 

Jesper de Jong wrote:Note that the stack trace of the exception tells you that the NullPointerException happens in line 81 of Calculator.java, in the constructor of class Calculator ("Calculator.<init>" means the constructor of Calculator).



Jesper & Henry,
thank you very much, it was really though for me to understand where the null could be being on the line of a for loop, in fact I was thinking, ehy this is a local variable represented by i, how it can be null, if I am iterating through the process?
I recompiled as you suggested and for some reason I completely ignored now is working flaweless, thank you again to support me, really appreciated now I know that a constructor is indicated with init, and this is pretty cool, because remember me the world of LInux.

I wish you an happy evening
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 793 times.
Similar Threads
calculator program help please
My Frame is not repainting itself after SWING conversion
Calculator clear button not working...
a challenge; contest if you will
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:17:02.