Foros del Web » Programación para mayores de 30 ;) » Java »

Error NullPointerException

Estas en el tema de Error NullPointerException en el foro de Java en Foros del Web. Hola! Tengo un error NullPointerException y no se como solucionarlo.. Acá va mi codigo: EL ERROR LO TIRA EN LA LINEA 54 @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código ...
  #1 (permalink)  
Antiguo 19/10/2013, 16:43
Avatar de elvaleehdj  
Fecha de Ingreso: julio-2011
Mensajes: 33
Antigüedad: 12 años, 9 meses
Puntos: 0
Error NullPointerException

Hola!

Tengo un error NullPointerException y no se como solucionarlo..

Acá va mi codigo:

EL ERROR LO TIRA EN LA LINEA 54

Código Java:
Ver original
  1. public class ChestRatioStorage {
  2.  
  3.  
  4.  
  5.     HashMap<Integer, ArrayList<ItemStack>>lvlstore = new HashMap<Integer, ArrayList<ItemStack>>();
  6.     public static ChestRatioStorage instance = new ChestRatioStorage();
  7.     int ratio = 2;
  8.  
  9.     private ChestRatioStorage(){
  10.  
  11.     }
  12.  
  13.     public void setup(){
  14.  
  15.         FileConfiguration conf = BGFiles.chest;
  16.  
  17.         for(int a = 1; a < 5;a++){
  18.             ArrayList<ItemStack> lvl = new ArrayList<ItemStack>();
  19.             List<String>list = conf.getStringList("chest.lvl"+a);
  20.  
  21.             for(int b = 0; b<list.size();b++){
  22.                 ItemStack i = ItemReader.read(list.get(b));
  23.                
  24.  
  25.                 lvl.add(i);
  26.             }
  27.  
  28.             lvlstore.put(a, lvl);
  29.  
  30.         }
  31.  
  32.         ratio = conf.getInt("chest.ratio") + 1;
  33.  
  34.     }
  35.  
  36.     public static ChestRatioStorage getInstance(){
  37.         return instance;
  38.     }
  39.  
  40.    
  41.  
  42.     public ArrayList<ItemStack> getItems(){
  43.         Random r = new Random();
  44.         ArrayList<ItemStack>items = new ArrayList<ItemStack>();
  45.         for(int a = 0; a< r.nextInt(7)+5; a++){
  46.             if(r.nextBoolean() == true){
  47.                 int i = 1;
  48.                
  49.                 while(i<6 && r.nextInt(ratio) == 1){
  50.                     i++;
  51.                 }
  52.                
  53.                 ArrayList<ItemStack>lvl = lvlstore.get(i);
  54.                 ItemStack item = lvl.get(r.nextInt(lvl.size()));
  55.                
  56.                 items.add(item);
  57.             }
  58.  
  59.         }
  60.  
  61.         //Bukkit.broadcastMessage(items+"");
  62.         return items;
  63.  
  64.  
  65.  
  66.     }
  67.  
  68.  
  69.  
  70.  
  71. }

No se que hacer!! Ayuda!
  #2 (permalink)  
Antiguo 20/10/2013, 23:38
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 7 meses
Puntos: 454
Respuesta: Error NullPointerException

Tiene pinta de que lvl es null.

Revisa el valor de i que estás usando para obtener lvl del hashmap. Por ejmplo, me llama la atención que cuando rellenas el hash uses i<5 y para obtenerlo uses i<6

Se bueno.
__________________
Apuntes Java
Wiki de Programación

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:35.