How to fix null object that appears all the time on my phone and sometimes on my emulator : got a probleme with Android studio. I'm trying to do a pretty simple app but on my phone (Galaxy S8) it always gives me the same error. And i use two computer it does the same at home and at school. When i use the emulator, i have the problem also on the emulator at home that is not the same from school but not in School.

So on the emulator at school, the one that works i had the same error as all the other place but juste once and ive tried it a lot of time. But later in the program i have the same kind of error that appears but in some other function. So far i havent been able to go past that.

The error is saying that im trying to do something on a null object (a layout or a text view). The error that happens always on my phone is as soon as i try to use a constraint layer it wont work. The other one that happens late in the program on the emulator seems really random. Its a game of card the 98 card game. And at some time when i try to drop a card on one of the pile it give me the null object error on the same textView. I have really tried but cant see any pattern on this one.

```
public Boolean checkEndOfGame(LinearLayout cartes, LinearLayout piles){
        if(nbCartes == 0){
            return true;
        }
        for (int i=0; i< piles.getChildCount(); i++){
            LinearLayout sorte = (LinearLayout)piles.getChildAt(i);
            for(int j=0; j< sorte.getChildCount(); j++){
                if(sorte.getChildAt(j) instanceof ConstraintLayout){
                    ConstraintLayout pile = (ConstraintLayout)sorte.getChildAt(j);
                    TextView textePile = (TextView) pile.getChildAt(0);
                    Integer noPile = new Integer(textePile.getText().toString());
                    for(int k=0; k< cartes.getChildCount(); k++){
                        LinearLayout rangee = (LinearLayout)cartes.getChildAt(i);
                        for(int l=0; l< rangee.getChildCount(); l++){
                            ConstraintLayout carte = (ConstraintLayout)rangee.getChildAt(l);
                            TextView texteCarte = (TextView) carte.getChildAt(0);
                            Integer noCarte = new Integer(texteCarte.getText().toString());
                            if(i>0){ //UP
                                if(noCarte>noPile){
                                    return false;
                                }
                            }else{ //DOWN
                                if(noCarte<noPile){
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }

        return true;

    }
```


So this is the function that gives me the random error always on that last TextView.

I give it carte and piles that are layout that contains each two other linearlayout. And in those there constraintLayout and in each constraintLayout theres a textView wich i can drag and drop.