• Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException  RSS feed

 
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Giovanni Montano
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!