Java - Arreglos

 
Vista:
sin imagen de perfil

Arreglos

Publicado por luis (5 intervenciones) el 14/05/2017 21:45:34
Buenas tardes, tengo un problema. Al momento de leer un archivo de propiedades, y pasarlo a un arreglo pareciera que el arreglo se repite.


1

Se supone que leo desde un fichero txt que contiene mis propiedades y paso el nombre y las caciones asociadas a este nombre a arreglos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
     * Carga la información inicial del karaoke.
     */
    private void cargarKaraoke() {
 
        try {
 
            Properties datos = new Properties();
 
            FileInputStream in = new FileInputStream(RUTA_ARCHIVO);
 
            datos.load(in);
 
            in.close();
 
            int numArtistas = Integer.parseInt(datos.getProperty("total.artistas"));
 
            for(int i = 1; i <= numArtistas; i++) {
 
                String nombre = datos.getProperty("artista" + i + ".nombre");
 
                String categoria = datos.getProperty("artista" + i + ".categoria");
 
                String imagen = datos.getProperty("artista" + i + ".imagen");
 
                karaoke.agregarArtista(nombre, categoria, imagen);
 
                int numCanciones = Integer.parseInt(datos.getProperty("artista"
                        + i + ".total.canciones"));
 
                for(int j = 1; j <= numCanciones; j++) {
                    String cancion = datos.getProperty("artista" + i + ".cancion"
                            + j + ".nombre");
                    int duracion = Integer.parseInt(datos.getProperty("artista"
                            + i + ".cancion" + j + ".duracion"));
                    String letra = datos.getProperty("artista" + i + ".cancion"
                            + j + ".letra");
                    int dificultad = Integer.parseInt(datos.getProperty( "artista"
                            + i + ".cancion" + j + ".dificultad"));
                    String genero = datos.getProperty("artista" + i + ".cancion"
                            + j + ".genero");
                    String ruta = datos.getProperty("artista" + i + ".cancion"
                            + j + ".ruta");
 
                    karaoke.agregarCancion(nombre, cancion, duracion, letra,
                            dificultad, genero, ruta);
 
                }
 
            }
 
        }
        catch(Exception e) {
 
            JOptionPane.showMessageDialog(this, "No fue posible cargar la información "
                    + "inicial del karaoke " + e.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
 
        }
 
    }

Pero al momento de probarlo aparecen los resultados de la imagen.

Aqui el metodo agregar artista, ya que creo que hay esta el problema, por cierto tiene un tamaño fijo de 10, por lo cual deberian salir los primeros 10 nombres registarados en mi archivo de propiedades.


1
2
3
4
5
6
7
8
9
10
11
public void agregarArtista(String nombreArtista, String categoria, String imagen) {
 
        for (int i = 0; i < artistas.length; i++) {
 
            artistas[i] = new Artista(nombreArtista, categoria, imagen);
 
        }
 
        System.out.println(Arrays.toString(artistas));
 
    }

¿Alguien tiene una idea de que pasa?

De antemano gracias por la ayuda.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder