error :Exception in thread "main" java.lang.Nullpointerexception

Asked

Viewed 1,780 times

0

I’m trying to set an attribute that’s a vector, and it’s in a class y, but I have a class x, which consists of this class y.

At the time I write the code there is no error, but when executing the following error appears to me:

error: Exception in thread "main" java.lang.Nullpointerexception at Ordering.milkMassas(Request.java:80)

how can I fix this?

Class y:classe y

Class x: classe X

  • 4

    Do not post code images, post code in text form, directly in question.

  • 5

    Lucas is not a good idea to put images with code, it only makes life difficult for those who want to help him, because then can not copy/Paste to test the code. http://answall.com/tour, http://meta.pt.stackoverflow.com/questions/5149/devemos-corta-a-mania-das-questions-imagem-do-c%C3%B3digo-ao-Inv%C3%A9s-do-c%C3%B3digo

  • Where the variable massas is it stated? What does it do? Please post your entire code, and for God’s sake post your code as text and not as images!

  • Check this out: http://answall.com/q/63617/132

1 answer

0


The mistake:

Exception in thread "main" java.lang.Nullpointerexception at Ordering.milkMassas(Request.java:80)

means that you are trying to do some operation on an object that is null! I usually say that it is the simplest error to be corrected in java, because it directs us exactly to that object! ;)

In the case of your code, your object "massas", in row 80 of the "Order" class (Class X) is void and you are trying to add a description to it.

Since I couldn’t test your code, I can just give you the hint to initialize your object before setting attributes on it.

A simple Massas massas = new Massas(); before the 80 line would solve your problem.

  • Good afternoon Dante, Thank you very much for the information, that’s right. Problem solved. I’m sorry I didn’t put the code, I’m new here and I didn’t know, but next time I do. !

  • You’re welcome, man! Mark my answer as correct and go? ;)

Browser other questions tagged

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