I am missing something here? NetBeans is saying that it’s expecting a “(” or “[” [closed]

public void getComputerPlayerTurn(String pid, ScopaCard card) {
    //checkPlayerTurn(pid);
    getPlayerHand(pid);
    int tempInt = playerHand.size();
    ArrayList<Rank> tempRanks = new ArrayList<Rank>           
        
    for (int i = 0; i < tempInt; i++) {
        card = playerHand.get(i).get(i);
        tempRanks.add(card.getRank());
    }
}

That’s my code for a method that I’m trying to create. The aim of this for loop is to get the cards in a players hand, and add their ranks to a different ArrayList. Everything is fine apart from the top line of the for loop (the one that has for (int i = 0; ...)). Here it is saying that a ( or [ is expected. I have no idea where though. Cheers.

Answer

ArrayList<Rank> tempRanks = new ArrayList<Rank>

You forgot to put the constructor’s brackets on the ArrayList. It should look like this:

List tempRanks = new ArrayList<>();

Leave a Reply

Your email address will not be published. Required fields are marked *