Android Activity Context is Null

后端 未结 5 1143
天涯浪人
天涯浪人 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:05

    I think mContext is not null, but the getResources() method return null.

    Change your code like below and try again, if it doesn't work. Paste the Logcat and we can debug the code.

    String[] list = mContext.getResources().getStringArray(R.array.championlist);
    

    and:

    public int[] getImage() {
    
        int[] tempImage = new int[list.length];
    
        for (int i = 0; i < list.length; i++) {
            tempImage[i] = mContext.getResources().getIdentifier(list[i],
                    "drawable", getPackageName());
        }
    
        return tempImage;
    
    }
    

提交回复
热议问题