Why are you giving this static variable error?

5

Why are you giving this compile error and how can I resolve this?

  

Can not make a static reference to the non-static field service

    
asked by anonymous 03.07.2016 / 21:21

1 answer

6

Because the method is static and the variable being used is instance . There is no relationship between them. Static members have the "owner" of the class. There is only one throughout the application. Instance members have as their "owner" the current instance, that is, each object created from this class owns its members. You can have as many as you want. Since the owners are different, it is not possible for a member to access the member of another owner.

The solution is to take the static of the method. It may be that the solution is to put static in the variable. I have no way of knowing what you have in the question.

    
03.07.2016 / 21:30