Hola y gracias de antemano por la colaboración.
Tengo un problema y es el siguiente, tengo este código:
Código:
public Discotienda( String nombreArchivoDiscotienda ) throws Exception
{
archivoDiscotienda = nombreArchivoDiscotienda;
discos = new ArrayList( );
cargarDiscotienda( new File( nombreArchivoDiscotienda ) );
verificarInvariante( );
}
private void cargarDiscotienda( File archivo ) throws Exception
{
int numeroDiscosD;
discos = new ArrayList();
// Construyo el lector del archivo
BufferedReader br = new BufferedReader( new FileReader( archivo ) );
// Leo el número de discos del archivo
String textoNumeroDiscos = br.readLine();
// Si la cadena está vacía o es un comentario (empieza con #), paso a la siguiente linea
while ( textoNumeroDiscos.startsWith("") || textoNumeroDiscos.startsWith("#") )
{
textoNumeroDiscos = br.readLine();
}
// Trato de leer el número de Discos
try
{
numeroDiscosD = Integer.parseInt( textoNumeroDiscos );
for ( int i = 0; i < numeroDiscosD; i ++ )
{
//discos.add( new Disco( br ) );
}
}
// So ocurriese algún problema leyendo el número de discos
catch ( Exception e )
{
throw new Exception("No se puede leer el número de discos: " + e.getMessage());
}
verificarInvariante();
br.close();
}
Supuestamente debe leer un archivo y leer dentro de el la primera linea que no esté en blanco ni comienza con el caractér # que signifíca un comentario, pero el problema es que cuando trato de ejecutarla me sale la siguiente información:
java.lang.NullPointerException
at Discotienda.cargarDiscotienda(Discotienda.java:84)
at Discotienda.<init>(Discotienda.java:58)
at InterfazDiscotienda.main(InterfazDiscotienda.java: 311)
que me lleva a la linea
while ( textoNumeroDiscos.startsWith("") || textoNumeroDiscos.startsWith("#") )... del código.
Será que estoy haciendo algo mal?