Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 08:20 PM   PM User | #1
trancecommunity
New Coder

 
Join Date: Feb 2013
Posts: 34
Thanks: 8
Thanked 0 Times in 0 Posts
trancecommunity is an unknown quantity at this point
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)
    {

        if ( !isFull(total) ){

            cars[total] = carIn;

            total++;
        }
        else{
            return false;
        }

        return true;

    }
Not sure what other info you need. Just ask.

Thanks
trancecommunity is offline   Reply With Quote
Old 02-26-2013, 09:59 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
trancecommunity (02-26-2013)
Old 02-26-2013, 10:30 PM   PM User | #3
trancecommunity
New Coder

 
Join Date: Feb 2013
Posts: 34
Thanks: 8
Thanked 0 Times in 0 Posts
trancecommunity is an unknown quantity at this point
Ah nice. Just had to create the object.

Thanks for the advice.
trancecommunity is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 AM.


Advertisement
Log in to turn off these ads.