Mathlight
Mathlight

Reputation: 6653

Cannot find symbol own class

I've got an package called superHeroNetwork. This is the default and only package.

I get the following error:

error: cannot find symbol
private ArrayList<superHero> helden;
                  ^
symbol:   class superHero
location: class superHeroNetworkSystem

Witch would suggest that the superHero class cannot be found. But the class exists in the same package.

I've tried to import all classes of the package ( import superHeroNetwork.*;) but that didn't fixed the problem to.

The file superHero.java:

package superHeroNetwork;

import java.util.ArrayList;

public class superHero {

    private String naam;
    private ArrayList<String> superKrachten;
    public ArrayList<superHero> vrienden;

    public superHero(String naam){
        this.naam = naam;
        this.superKrachten = new ArrayList<String>();
        this.vrienden = new ArrayList<superHero>();
    }
}

And the file superHeroNetworkSystem.java:

package superHeroNetwork;

import java.util.ArrayList;

public class superHeroNetworkSystem {

    private ArrayList<superHero> helden;

    public superHeroNetworkSystem(){
        this.helden = new ArrayList<superHero>();
    }

    public void voegSuperheldToe(superHero held){
        this.helden.add(held);
    } 

    public void voegVriendschapToe(superHero vriend1, superHero vriend2){
        if(!vriend1.vrienden.contains(vriend2)){
            vriend1.addFriend(vriend2);
            vriend2.addFriend(vriend1);
        }else{
            System.out.println("Jullie zijn al vrienden!");
        }
    }
}

I'm clueless right now on how to fix this problem. How can i solve this particular problem?

Upvotes: 2

Views: 488

Answers (1)

Maroun
Maroun

Reputation: 95948

The problem is that you're not compiling from the source directory.

I would like to add some few notes:

  • follow Java Naming Conventions and rename your class to SuperHero also change your package name

  • do you really want vrienden to be public member of the class? I'm not sure about what your class suppose to do, but looks like you can improve it (think about getters and setters)

Upvotes: 2

Related Questions