I have a string variable
static String[] genrename;
I am assigning values to it in one of my method and then displaying its content. It does store the value fine. But when I am accessing the String variables directly or from a getter method(). It shows a null value in the string.
Any ideas?
public class GenreParsing {
static int entries;
static String[] genrecode;
static String[] genrename;
public GenreParsing() {
}
public void parsing(String returnContent) {
try {
JSONObject jo_genres = new JSONObject(returnContent);
System.out.println(jo_genres);
JSONArray ja_genres = jo_genres.getJSONArray("genres");
System.out.println(ja_genres);
entries=ja_genres.length();
for (int i = 1; i < entries; i++) {
JSONObject jo_genre = (JSONObject) ja_genres.get(i);
JSONArray ja_genre = jo_genre.getJSONArray("genre");
JSONObject genreinfo = (JSONObject) ja_genre.get(0);
genrecode = new String[entries];
genrename = new String[entries];
genrecode[i] = genreinfo.getString("code");
genrename[i] = genreinfo.getString("name");
System.out.println(genrecode[i]);
System.out.println(genrename[i]);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
public int no_of_entries() {
System.out.println(entries);
return entries;
}
public String getgenrecode(int x) {
System.out.print(genrecode[x]);
return genrecode[x];
}
public String getgenrename(int y) {
return genrename[y];
}
}