user12372969
user12372969

Reputation:

Can't find symbol when I try to create an object

When I try to javac my Persoon.java, it is going well but when I try to compile my Main it keeps saying this:

symbol:   class Persoon
location: package maandelijkseKosten
Main.java:7: error: cannot find symbol
                Persoon tim = new Persoon();

symbol:   class Persoon
location: class Main
Main.java:7: error: cannot find symbol
                Persoon tim = new Persoon();

I tried to find an answer online but without success, so I hope someone here can help me with this. Here is my code:

package maandelijkseKosten;

public class Persoon {
    private String voorNaam = "";

    public Persoon() {
    }

    public Persoon(String voorNaam) {
        this.voorNaam = voorNaam;
    }

    public String getVoorNaam() {
        return voorNaam;
    }

    public void setVoorNaam(String voorNaam) {
        this.voorNaam = voorNaam;
    }
}

Main class:

package maandelijkseKosten;

public class Main {
    public static void main(String[] args) {
        Persoon tim = new Persoon();
    }
}

Upvotes: 0

Views: 65

Answers (1)

Vitaly Roslov
Vitaly Roslov

Reputation: 323

As people say in the comments, you probably have incorrect directory structure. Here is how it should look:

> tree                                                                                                                                                   
.
└── maandelijkseKosten
    ├── Main.java
    └── Persoon.java

1 directory, 2 files
> javac maandelijkseKosten/Persoon.java                                                                                                                  
> javac maandelijkseKosten/Main.java                                                                                                                     
> tree                                                                                                                                                   
.
└── maandelijkseKosten
    ├── Main.class
    ├── Main.java
    ├── Persoon.class
    └── Persoon.java

1 directory, 4 files
> java maandelijkseKosten.Main 

Upvotes: 1

Related Questions