Shop OBEX P1 Docs P2 Docs Learn Events
NullPointerException — Parallax Forums

NullPointerException

EnriqueEnrique Posts: 90
edited 2007-09-05 21:17 in General Discussion
Hi,
·
The attached program generates a NullPointerException at line 48, which happens to be the System.out.println statement. I have two questions:
·
a.-·· Why does it happen?
b.-·· How do I correct it?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-09-05 21:17
    The problem is that System.out.println() may not yet be initialized
    because it is called before main() executes.
    Use the constructor of class FourDigits to pass values and initialize
    the class variables.
    Add a new method to the class FourDigits that prints out the values you want.
    Call this new method from main().
    That should resolve the issue.

    But you may want to try first to define FourDigits public.
    public FourDigits(...)

    regards peter
Sign In or Register to comment.