I am sorry for I am a beginner.
I try to put the value into string name[], int age [], int hand[], but all the value is null.
I don't know which part have problem. Since i learn this from youtube.
I just want to store the data to array.
Thank you
public class main extends AppCompatActivity {
String oName[] = new String [];
int oAge [] = new int [];
int oHand [] = new int [];
protected void onCreate(Bundle savedInstanceState) {...}
private class DownloadTask extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground (String... values) {
InputStream is = null;
String result = ""; //Get json?
String line;
try {
URL ua = new URL("https://api.myjson.com/bins/r5kim"); //json address
HttpURLConnection conn = (HttpURLConnection) ua.openConnection();
conn.setRequestMethod("GET");
conn.connect();
is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
result += line;
}
is.close();
JSONObject jo = new JSONObject(result); //get json
JSONArray op = jo.getJSONArray("opponents"); //json array?? parse??
for(int i = 0; i < op.length(); i++) {
oName[i] = op.getJSONObject(i).getString("name"); //Get null
oAge[i] = op.getJSONObject(i).getInt("age"); //Get null
oHand[i] = op.getJSONObject(i).getInt("hand"); //Get null
}
} catch (MalformedURLException e) { //exception
e.printStackTrace();
} catch (IOException e) { //exception
e.printStackTrace();
} catch (JSONException e) { //exception
e.printStackTrace();
}
return null;
}
}