I tell you, I have this class on one side
static class Item implements Serializable {
int Id;
String nombre, descripcion;
int tipo; //{1-armas, 2-armadura, 3-miscelánea}
int experiencia;
} //fin clase Item
I also have a method where I fill an array with Potions of this class, for example PocimaVida25 ... I have to show this array, when I put this code:
System.out.println("Tus ítems son los siguientes: ");
for(int j = 0; j <= listaItems.length; j++) {
System.out.println(j + 1 + ": " + listaItems[j].nombre);
}
I get this appears, that is, I shows them well but then tells me that points to a null site, and I do not know how to fix it:
Tus ítems son los siguientes:
1: Espadas de Kratos
2: Arco de Diana
3: Escudo de la Gorgona
Exception in thread "main" java.lang.NullPointerException
My other doubt is that in another exercise I have to make it appear alphabetically, and in this I do not know how to do it, I read on the internet that you can use an instruction called sort, but that has not been taught to us in class so I do not think I can use it: At the moment I have this, but I do not know how to go about comparing it, or I'm even going well:
public static void MostarItemAlfabeticamente(Item [] listaItems, int MAXITEMS, Item golem, Item esqueleto, Item kratos, Item diana,Item sabiduria, Item gorgona ){
for(int i = 0;i < listaItems.length;i++){
char primeraLetra = listaItems[i].nombre.charAt(1);
}
}
Greetings!