![]() |
non-static method addCar() cannot be referenced from a static context
Trying to call this function. Point being it adds an object called carNew into an array and increases total by 1. Then returns a "true" that can print out a success message.
Code:
boolean ok = CarShowRoom.add(carNew);Code:
public boolean add(Car carIn)Thanks |
public boolean add(Car carIn);The signature here indicates that this is an object context method, but the call is that on CarShowRoom.add which is static. You need to construct an instance of CarShowRoom in order to .add to it, or flag the method as static. If the cars array is static and the total is static, than the method can be flagged as static. Otherwise, you need to instantiate CarShowRoom in order to invoke the .add. |
Ah nice. Just had to create the object.
Thanks for the advice. |
| All times are GMT +1. The time now is 06:37 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.