Link to home
Start Free TrialLog in
Avatar of morsa804tons
morsa804tons

asked on

static method error

Hi!

i'm trying to implement a simple application consisting of this classes:

/*
 * Concesionari.java
 *
 * Created on 14 de abril de 2006, 2:40
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */



package concesionario;

import java.io.*;
import java.util.*;



/**
 *
 *
 */
public class Concesionari {

    String name;
    Store concesionari;
   
   
       
    /** Creates a new instance of Concesionari */
    public Concesionari() {
          this.name = name;
      concesionari = new Store();
   
    }
 

 

public boolean add(Vehicle vehiculo) {
            return Store.add(vehiculo);
      }
 
}



/*
 * Vehicle.java
 *
 * Created on 13 de abril de 2006, 3:59
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package concesionario;

/**
 *
 * @author jolivan
 */


public class Vehicle {
   
    private float preu;
    private int any;
    private String model;
    private String numplate;
   
   
    /** Creates a new instance of Vehicle */
    public Vehicle(float preu, int any, String model, String numplate) {
                       
        setPreu(preu);
        setAnyFabricacio(any);
        setModel(model);
        setMatricula(numplate);
        getMatricula();
    }
   
   
    void setPreu(float preu) {
    this.preu = preu;
    }
   
    void setAnyFabricacio(int any) {
    this.any = any;
    }
   
    void setModel(String model) {
    this.model = model;
    }
   
    void setMatricula(String numplate) {
    this.numplate = numplate;
    }
   
    String getMatricula(){
        return this.numplate;
    }

}



/*
 * Store.java
 *
 * Created on 15 de abril de 2006, 5:57
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package concesionario;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


/**
 * Aggregate of products for sale
 *
 * @author UOC
 * @version 1.0
 */
public class Store {
      /**
       * Product container
       *
       * @see Collection
       */
      private List vehiculos;

      /**
       * By default, the store uses an <code>ArrayList</code> as container
       */
      public Store() {
            vehiculos = new ArrayList();
      }
      
      /**
       * Class constructor. The store is created as the contained implementation
       * is specified (this must have been created)
       *
       * @param products
       *            Container to be used
       * @throws NullCollectionException
       *             The container has not been created
       */
      public Store(List vehiculos) {
            if (vehiculos != null) {
                  this.vehiculos = vehiculos;
            }
      }

      /**
       * Adds a product to the store
       *
       * @param product
       *            Product to add
       * @return <code> true </code> if correct. Otherwise <code> false </code>
       */
      public boolean add(Vehicle vehiculo) {
            return vehiculos.add(vehiculo);
      }

      /**
       * Removes a product from the store
       *
       * @param product
       *            Product to remove
       * @return <code> true </code> if correct. Otherwise <code> false </code>
       */
      public boolean remove(Vehicle vehiculo) {
            return vehiculos.remove(vehiculo);
      }

      /**
       * Shows the list of products in the store.
       */
      public void show() {
            List copy = new ArrayList(vehiculos);
            Collections.sort(copy);
            Iterator iterator = copy.iterator();
            while (iterator.hasNext()) {
                  System.out.println((Vehicle)iterator.next());
            }
      }

}



But when i tried to compile: C:\Documents and Settings\Administrador\Mis documentos\UOC\POO\Concesionario\src\concesionario\Concesionari.java:42: non-static method add(concesionario.Vehicle) cannot be referenced from a static context
                return Store.add(vehiculo);

and i cannot see where is the static context i'm referencing to... can u help me plz? =)

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morsa804tons
morsa804tons

ASKER

yes, i finally found it... instance name was "concesionari" and i put Store, instance's type.

Thanx for your help!
No problem
:-)