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

Problema desconocido com proyecto en Netbeans 5.5

Estas en el tema de Problema desconocido com proyecto en Netbeans 5.5 en el foro de Programación General en Foros del Web. Saludos amigos, estoy haciendo un programa q almacena datos dentro de un ArrayList y luego tiene q almacenarlos en archivo txt, el programa guarda los ...
  #1 (permalink)  
Antiguo 04/08/2007, 18:54
 
Fecha de Ingreso: agosto-2007
Mensajes: 11
Antigüedad: 16 años, 9 meses
Puntos: 1
De acuerdo Problema desconocido com proyecto en Netbeans 5.5

Saludos amigos, estoy haciendo un programa q almacena datos dentro de un ArrayList y luego tiene q almacenarlos en archivo txt, el programa guarda los datos muy bien, sin embargo me da un error "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0"; ya lo revise y se supone q eso sucede si mi ArrayList estuviera vacio pero si tiene datos les agradeceria un monton q me ayuden Gracias.....
A con tinuacion les envio el codigo del JFrame Form y el de la Clase

El JFame Form

import java.io.*;
import java.util.ArrayList;

public class Principal extends javax.swing.JFrame {
private Datos d;
private ArrayList <Datos> lista;

public Principal() {
initComponents();
lista=new ArrayList <Datos>();
}
//Un Boton Guardar
private void guardarActionPerformed(java.awt.event.ActionEvent evt) {
try
{
// guarda todos los registros de empleados a el archivo empleado.dat
PrintWriter out = new PrintWriter(new FileWriter("Datos.txt"));
escribirDato(lista, out);
out.close();

// recupera todos los registros en un nuevo arreglo
BufferedReader in = new BufferedReader(new FileReader("Datos.txt"));
ArrayList <Datos> newLista = leerDato(in);
in.close();

// escribe el nuevo arrelo de empleados
for (Datos e : newLista)
System.out.println(e);
}
catch(IOException exception)
{
exception.printStackTrace();
}
}

//Un Boton Aceptar
private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {
d=new Datos(nom.getText(),edad.getText(),telf.getText(), direc.getText(),ci.getText());
lista.add(d);
Borrar();
}

//Metodos

static void escribirDato(ArrayList <Datos> lista, PrintWriter out)
throws IOException
{
// escribe el numero de empleados
out.println(lista.size());

for (Datos dato : lista)
dato.writeData(out);
}
/////////////////////////////////////////////////////////////////////////////
static ArrayList leerDato(BufferedReader in)
throws IOException
{
// recupera la medida del arreglo
int n = Integer.parseInt(in.readLine());

ArrayList <Datos> lista = new ArrayList<Datos>();
for (int i = 0; i < n; i++)
{
lista.get(i).readData(in);
/*Empleados[i] = new Empleado();
Empleados[i].readData(in);*/
}
return lista;
}
////////////////////////////////////////////////////////////////////////////////
public void Borrar(){
nom.setText("");
edad.setText("");
telf.setText("");
ci.setText("");
direc.setText("");
}
//Nota: Son 5 JTexField

//El Codigo de la Clase

import java.io.*;
import java.util.*;

public class Datos {

private String nombre;
private String edad;
private String telef;
private String direc;
private String ci;

public Datos() {
}

public Datos(String n,String e,String t,String d,String c) {
setNombre(n);
setEdad(e);
setDirec(d);
setTelef(t);
setCi(c);
}

public String getNombre() {
return nombre;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public String getEdad() {
return edad;
}

public void setEdad(String edad) {
this.edad = edad;
}

public String getTelef() {
return telef;
}

public void setTelef(String telef) {
this.telef = telef;
}

public String getDirec() {
return direc;
}

public void setDirec(String direc) {
this.direc = direc;
}

public String getCi() {
return ci;
}

public void setCi(String ci) {
this.ci = ci;
}

///////////////////////////////////////////////////////////////////////////
public String toString()
{
return getClass().getName()
+ "[nombre= " + nombre
+ ",edad= " + edad
+ ",telef= " + telef
+ ",direc= "+ direc
+ ",ci= " +ci
+ "]";
}

public void writeData(PrintWriter out) throws IOException
{
out.println(nombre + "|"+ edad + "|"+ telef + "|"+ direc + "|"+ ci);
}

public void readData(BufferedReader in) throws IOException
{
String s = in.readLine();
StringTokenizer t = new StringTokenizer(s, "|");
nombre = t.nextToken();
edad = t.nextToken();
telef= t.nextToken();
direc =t.nextToken();
ci = t.nextToken();
}

}


Disculpen por enviar el codigo asi lo que pasa es no se me permitio adjuntar el archvo, les agradesco de ante mano por su ayuda GRACIAS.....
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 22:40.