(Java noob) PokeAPI JSONObject nullpointerexception

Hi, I'm trying to load data from the PokeAPI into an array so I can have an array containing each pokemon. Here is my code:

import http.requests.*;

class Pokemon {
  int pid, pheight, pweight;
  String pname, front;

Pokemon Stats[] = new Pokemon[151];

for (int i = 1; i <= 151 ; i++){
  GetRequest get = new GetRequest("http://"+"pokeapi.co/api/v2/pokemon/" + i);
  JSONObject stat = parseJSONObject(get.getContent());

  Stats[i].pname = stat.getString("name");
  Stats[i].pid = stat.getInt("id");
  Stats[i].pheight = stat.getInt("height");
  Stats[i].pweight = stat.getInt("weight");
  Stats[i].front = stat.getString("front_default");

It throws up a nullpointerexception during the loop on the getString function, and I can't for the life of me figure out why. Any tips? Sorry if this is a stupid mistake I've never done anything like this before.


Sign In or Register to comment.