java - Array nullpointerException ERROR -
java - Array nullpointerException ERROR -
here partial code:
`private instrumento[] repinst;  public repositorioinstrumentos(){     instrumento[] repinst = new instrumento[20];  }  private int getpos(int id){         int pos= -1;         for(int i=0; i<tam; i++){             if (repinst[i]!=null&&repinst[i].getid()==id){                 pos=i;                 i=tam;             }         }          homecoming pos;     }`    i maintain getting null poiter exception in line:
 `if (repinst[i]!=null&&repinst[i].getid()==id){`    all positions of repinst null. thought putting " if " skip , homecoming pos = -1.
why isn't working?
repinst local varible in constructor
private instrumento[] repinst; public repositorioinstrumentos(){  repinst = new instrumento[20];  } private int getpos(int id){     int pos= -1;     for(int i=0; i<tam; i++){         if (repinst[i]!=null&&repinst[i].getid()==id){             pos=i;             i=tam;         }     }      homecoming pos; }        java arrays nullpointerexception 
 
Comments
Post a Comment