.getExtras()' on a null object reference

天涯浪子 提交于 2019-12-02 10:40:29

Move

Bundle extras = getIntent().getExtras();

ArrayList<Integer> players = extras.getIntegerArrayList("players");
int currentPlayer = extras.getInt("newPlayerNum");

into onCreate(). getIntent() needs a Context which isn't available before onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_three_sign_game);

    // here
     Bundle extras = getIntent().getExtras();

     ArrayList<Integer> players = extras.getIntegerArrayList("players");
     int currentPlayer = extras.getInt("newPlayerNum");
}

Wait until onCreate to get the intent. Your trying to getIntent() when the class is instantiated instead of when the Activity is active.

Then just assign the values found to a field and other methods inside that class can access the field.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!