I have an activity and am getting a nullPointerException on the last line of the clicked method
public class MainActivity extends AppCompatActivity {
List<Item> it;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clicked(View view) {
getCompany(s);
Integer.toString(it.size());
}
public void getCompany(String name) {
apiCall.setCallback(new ApiCall.NetworkCallback() {
@Override
public void onResponse(List<Item> items) {
it = items;
for (int i = 0; i < items.size(); i++) {
Log.d("Name", it.get(i).getTitle());
}
}
});
}
I have removed some of the code to keep it short but the issue is the 'it' list is accessible in the onResponse method but gives a nullPointerException in the clicked method.
What would be causing this and how can I store the list to be used outside of the onResponse method?