I am making an Android Java Application. I have a class with a function which uses Volley to get me 2D string array from my databse.
Since I cannot return the string array from the function I created (Since I'm using volley), I saved it in a static variable of another class.
In my main activity, I call the class which gets me the string array and it assigns it to the static variable.
The problem is that before my string array is received by the classes, the 2D array is used by my main activity and since the string array is undefined. It gives me a null pointer exception.
I need to let the initialization of string array first and then have it be used my main acitivty.
CodePudding user response:
the initialization of string array should be done on onResponse() if you have made the String array initialization in the main thread you will get the error that you have mentioned above. You should only invoke the string array on the volley thread only.