NullPointerException from getExtras()

后端 未结 3 828
青春惊慌失措
青春惊慌失措 2021-01-05 06:50

I\'m creating an intent to transfer data from one activity to another like this :

Intent intent = new Intent(this, ActivityHighScore.class);
    intent.putE         


        
3条回答
  •  逝去的感伤
    2021-01-05 07:15

    Well, I had a similar problem. In my case the NullPointerException happened when I checked if my bundle.getString() was equal to null.

    Here is how I solved it, in my case:

    Intent intent = getIntent();        
    if(intent.hasExtra("nomeUsuario")){
        bd = getIntent().getExtras();
        if(!bd.getString("nomeUsuario").equals(null)){
            nomeUsuario = bd.getString("nomeUsuario");
        }
    }
    

提交回复
热议问题