Arraylist of arraylist in method
android, arraylist, java
Solution
You never actually initialize either of those arraylists.
You want
ArrayList<ArrayList<String>> mainArray = new ArrayList<ArrayList<String>>(); // or new ArrayList<>() in java 7
and inside the inner for loop:
ArrayList<String> innerArrays = new ArrayList<String>(); // or new ArrayList<>() in java 7
Also, don't ever suppress warnings "just to make code work". Only suppress them when you know exactly why they appear and exactly why you're choosing to ignore them.
Problem
having a problem trying to get an arraylist containing arraylists to work in my program, Im getting a strange warning saying: add @SuppressWarnings "null" to processArray(), regardless of If I add this or not my program crashes, Is there anything obvious that Im doing wrong here? any help would go a long way thanks. ``` private ArrayList<ArrayList<String>> processArray(ResponseList<Status> responses){ ArrayList<ArrayList<String>> mainArray = null; ArrayList<String> innerArrays = null; for (Status response: responses ){ String name, status, imgUrl, time; name = response.getUser().getName(); status = response.getText(); imgUrl = response.getUser().getProfileImageURL().toString(); time = response.getCreatedAt().toString(); ArrayList<String> rtLinks = checkLinks(response.getText()); if(rtLinks != null){ for (String tLink: rtLinks){ innerArrays.add(name); innerArrays.add(status); innerArrays.add(imgUrl); innerArrays.add(time); innerArrays.add(tLink); mainArray.add(innerArrays); } } } return mainArray; ```