Chloé
Chloé

Reputation: 21

"Cannot be resolved to a type" in eclipse

I am very new in trying to learn to code in java.

I have done some tutorials and exercises from English speakers, but if I try to use code from my native language (Danish) programming books, I get a lot of errors in eclipse. They mostly consist of "cannot be resolved to a variable/type".

E.g. in the following code, the first errors I get is

spillere cannot be resolved or is not a field

and

Spiller cannot be resolved to a type

Is there something missing I need to declare? Hope this is enough information for any help :)

public class Matadorspil {

    public static void main(String[] args) {
        Matadorspil spil = new Matadorspil();
        spil.spillere.add(new Spiller("Søren", 50000));
        spil.spillere.add(new Spiller("Gitte", 50000));

        for (spil.spillersTur = 0; spil.spillersTur < 40; spil.spillersTur++) {
            Spiller sp = spil.spillere.get(spil.spillersTur % spil.spillere.size());
        }
        int slag = (int) (Math.random() * 6) + 1;
        System.out.println("***** " + sp.navn + " på felt " + sp.feltnr + " slår " + slag);

        for (int i = 1; i <= slag; i = i + 1) {
            sp.feltnr = sp.feltnr + 1;
        }

        if (sp.feltnr == spil.felter.size()) {
            sp.feltnr = 0;
        }

        Felt felt = spil.felter.get(sp.feltnr);

        if (i < slag) {
            felt.passeret(sp);
        } else {
            felt.landet(sp);
        }

        try {
            Thread.sleep(300);
        } catch (Exception e) {

        }

        try {
            Thread.sleep(3000);
        } catch (Exception e) {

        }
    }
}

Upvotes: 1

Views: 1109

Answers (1)

Paulo
Paulo

Reputation: 1498

That hasn't to do with your language. When you do spil.spillere, you must have this field (spillere) in the class Matadorspil. That's why you got the first error. For the second error, you must either create a class named Spiller or import the class from its package. Maybe, you didn't copy the code entirely. Come back to the place where you learned, and check it out.

Upvotes: 2

Related Questions