I'm getting a NullPointerException when i'm checking if the length of the array is equal to 0 or not, and I can't find why it isn't working. Anyone could tell me what i'm doing wrong ? Here's my entire function code:
public static ArrayList<String> searchZone(Player p){
openConnection();
ArrayList<String> data = new ArrayList<String>();
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
Selection selection = worldEdit.getSelection(p);
String query = "SELECT * FROM " + db + ".blocks";
ArrayList<String> res = executeQueryWe(query);
String[] items = res.toArray(new String[res.size()]);
int i = 0;
int iters = items.length;
while(i < iters){
try{
if(selection != null){
String[] locs = items[i].split(",");
World world = Bukkit.getServer().getWorld(locs[0]);
int x = Integer.valueOf(locs[1]);
int y = Integer.valueOf(locs[2]);
int z = Integer.valueOf(locs[3]);
Location loc = new Location(world, x, y ,z);
if(selection.contains(loc)){
String query2 = "SELECT * FROM `blocks` WHERE `world`='" + world.getName() + "' AND `x`='" + x + "' AND `y`='" + y + "' AND `z`='" + z + "';";
data = executeQuery(query2);
}
}
} catch(Exception e){
closeConnection();
p.sendMessage(prefix + ChatColor.RED + "An error occured while reading database");
break;
}
p.sendMessage(prefix + ChatColor.RED + "Please make a selection first");
break;
}
if(data.size() != 0){ //<---------------------------- ERROR COMES FROM HERE
closeConnection();
return data;
} else {
data.add("No entries has been found.");
closeConnection();
return data;
}
}