0

i'm practicing creating apps and i have a problem that i don't understand : why i'm getting this error with this code :

    java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.baziremartin.pyramideapp.paquet.getCartes(int)' on a null object reference

the code :

 mTestBTN.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<joueur> currentPlayers = new ArrayList<>();
                for(int i = 0; i < allPlayers.size(); i ++){
                    currentPlayers.add(new joueur(allPlayers.get(i)));
                    currentPlayers.get(i).setHand(paquet1.getCartes(4));

                }
            }
        });

I've already search and i think it is a reference syntaxe error but i don't understand whats is the good syntax.. (i have try a lot of differents things). Thanks for help i'm beginner in java.

  • 1
    Where is `paquet1` declared? Where is it initialized? – Eran Feb 27 '20 at 09:47
  • 1
    There are multiple issue with your code. First of all, please post all relevant code. Now we don't see, as @Eran pointed out, where `paquet1` is declared. Its almost certain that no value is assigned to `paquet1`. You should trace why this is. – Jeroen Peeters Feb 27 '20 at 09:54
  • @JeroenPeeters Thank's a lot i finally understand where my mistake was. I was so focusing on reference because it was the main problem of the others. There was a mistake in paquet1. – Martin Bazire Feb 27 '20 at 10:27

0 Answers0