Error when instantiating an object

Asked

Viewed 291 times

1

When I will instantiate the object Vendedor this error appears:

java.lang.NullPointerException
    at Vendedor.<init>(Vendedor.java:9)

I’d like to know what it means and how to fix it?

2 answers

2

The exception NullPointerException is launched when the program tries to use the reference of an object with null value. See an example:

public static void main (String[] args) throws java.lang.Exception
{
    String foo = null;
    System.out.println(foo.toString()); // NullPointerException será lançada
}

1


It means that a NullPointerException on line 9 of the Seller.java file

Solution:

Don’t cause a NullPointerException :-)

Tip: anythingVariable.anything() cause Nullpointerexception if anythingVariable is null.

  • 2

    It would be nice if you could provide more information in your reply and make it richer.

  • 1

    I believe an explanation about what is a null pointer exception, as well as a suggestion on how to find the code snippet that may be causing it, would make the answer acceptable.

  • Well, the answer was short and thick, but it’s all there: I indicated line 9 (which I don’t know what has, because the code was not posted), and an example of a situation that causes the exception. I just didn’t put much theoretical explanation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.