Error in java code

Asked

Viewed 41 times

0

I’m starting to learn programming in java, and the following happened:

ERRO!!!!!
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Player cannot be resolved to a type
Player cannot be resolved to a type

at oo/oo.main.main(main.java:5)
package oo;

public class jogador {
    public void startplayer() {
        System.out.println("Player started");
    }
}



package oo;

public class inimigo {
    public void startenemy() {
        System.out.println("Enemy started");
    }
}

package oo;

public class main {
    public static void main (String[] args) {
        Player player = new Player();
        player.startplayer();
    }
    
}

2 answers

3

Welcome to our community!

The error mentioned is that basically your "Player" class does not exist, so it is not possible to create an instance, see:

Player player = new Player();

Then rename the player class to Player and take the test. Remember, also if that class is in a separate file. The file name should be Player.java and not player.java

public class Player

instead of

public class jogador

3

your code has some problems, I will explain about the error and the other problems I see.

  • in the main method you are trying to instantiate a Player, this class does not exist, the one you wrote is called gambler.

  • good practices recommend the name of classes Camelcase and starting with capital letters. Also in this idea of names and to avoid problems like this that you are having, avoid using mixed languages in your code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.