Android Activity Context is Null

后端 未结 5 1149
天涯浪人
天涯浪人 2021-01-27 09:49

So I have these Codes here, It runs without crashing. However When I pass \"this\" into the gridadapter the mContext is null. I tried to pass getApplicationContext() through but

5条回答
  •  无人共我
    2021-01-27 10:06

    The root of your problem is that you are trying to initialize a member variable inline with

    int[] champImage = getImage();
    

    This executes before the constructor which sets mContext to a valid value. However, the fact that mContext is null inside the call for getImage() should be irrelevant because you never actually use mContext in that method.

    The overall issue is that you need to be careful about the order of execution.

提交回复
热议问题