Fabian van Rooyen
Fabian van Rooyen

Reputation: 13

Java cannot find symbol - method hashset

I Have a problem with my java application, the class verhuur inherits from bedrijf. In Bedrijf i want to acces the method getBegintijd from the class verhuur although i get the error cannot find symbol - method getBegintijd.

Can somebody help me?

Class Bedrijf:

// instance variables
private HashSet<Verhuur> verhuur;

/**
 * Constructor for objects of class Bedrijf
 */
public Bedrijf()
{
    // initialise instance variables
    this.verhuur = new HashSet<Verhuur>();
}

/**
 * 
 */
public void add(Verhuur verhuur)
{
    this.verhuur.add(verhuur);
}

/**
 * 
 */
public void getBegintijd()
{
    System.out.println(verhuur.getBegintijd());
}

Class Verhuur

    // instance variabelen
private String Begintijd;
private String Eindtijd;
private int GebruikteBrandstof;
private boolean Schade;
private Boot boot;

/**
 * Constructor for objects of class Verhuur
 */
public Verhuur(String Begintijd, String Eindtijd, int GebruikteBrandstof, boolean Schade, Boot boot)
{
    // intialiseer instance variabelen
    this.Begintijd = Begintijd;
    this.Eindtijd = Eindtijd;
    this.GebruikteBrandstof = GebruikteBrandstof;
    this.Schade = Schade;
    this.boot = boot;
}

/**
Return de Begintijd
 */
public String getBegintijd()
{
    return Begintijd;
}

/**
Return de Eindtijd
 */
public String getEindtijd()
{
    return Begintijd;
}

    /**
Return de GebruikteBrandstof
 */
public int getGebruikteBrandstof()
{
    return GebruikteBrandstof;
}

    /**
Return de begintijd
 */
public boolean getSchade()
{
    return Schade;
}

Upvotes: 0

Views: 2289

Answers (1)

Eran
Eran

Reputation: 394016

verhuur is a HashSet<Verhuur>, so in order to call the getBegintijd() method of your Verhuur class you must obtain an element from the HashSet.

For example, the following code will call the getBegintijd() method for the first element returned by the Set's iterator :

public void getBegintijd()
{
    if (!verhuur.isEmpty())
        System.out.println(verhuur.iterator().next().getBegintijd());   
    else
        System.out.println("empty set");
}

Upvotes: 0

Related Questions