Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/01/2009, 16:48
robinn
 
Fecha de Ingreso: enero-2009
Mensajes: 7
Antigüedad: 15 años, 3 meses
Puntos: 0
Exception in thread "main" java.util.NoSuchElementException

Hola a todos me sale el siguiente error cuando compilo un codigo de java sdk en eclipse

Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(Unknown Source)
at stock.elimina_stockHerramienta(manejaTool.java:83)
at manejaTool.main(manejaTool.java:161)

el codigo es el siguiente:

class stock{
private String tipo, codigo, cantidad, nombre;
private int cantMinima;



public stock(){}


public String consulta_stockHerramienta(String nom)throws java.io.IOException,java.io.FileNotFoundException{
String str = new String();
BufferedReader lee;
lee=new BufferedReader(new FileReader("stock.dat"));

while( (str=lee.readLine() )!=null){
StringTokenizer strtk=new StringTokenizer(str, "/");

for(int i=0; strtk.hasMoreTokens(); i++){
codigo = strtk.nextToken();
tipo=strtk.nextToken();
nombre=strtk.nextToken();

if(nombre.compareTo(nom)==0)
return str;
}
}
return "0";
}

public void elimina_stockHerramienta(String nom)throws java.io.IOException,java.io.FileNotFoundException{
String str1=consulta_stockHerramienta(nom);
StringTokenizer strtk1=new StringTokenizer(str1,"/");

codigo = strtk1.nextToken();
tipo = strtk1.nextToken();
nombre = strtk1.nextToken();
cantidad = strtk1.nextToken();

int cant=Integer.parseInt(cantidad);
cant=cant-1;
cantidad = String.valueOf(cant);

str1=codigo.concat("/");
str1=str1.concat(tipo);
str1=str1.concat("/");
str1=str1.concat(nombre);
str1=str1.concat("/");
str1=str1.concat(cantidad);
//System.out.println(str1);

stock aux[]=new stock[100];
String str2 = new String();
String cod = new String();
String tip = new String();
String nomb = new String();
String canti = new String();
BufferedReader lee;
lee=new BufferedReader(new FileReader("stock.dat"));
//System.out.println(codigo);

while( (str2=lee.readLine() )!=null){
StringTokenizer strtk=new StringTokenizer(str2, "/");


for(int i=0; strtk.hasMoreTokens(); i++){
cod=strtk.nextToken();

if(cod.equals(codigo)==true)
continue;
tip=strtk.nextToken();
nomb=strtk.nextToken();
canti=strtk.nextToken();
//System.out.println(cod);
/*aux[i].codigo=cod;
aux[i].tipo=tip;
aux[i].nombre=nomb;
aux[i].cantidad=canti;
System.out.println(aux[i]);*/
}



}

/*FileWriter fw= new FileWriter("stock.dat");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter salida=new PrintWriter(bw);
salida.println(str1);
salida.close();
String str2=new String();

for(int i=0; i<aux.length; i++){
str2=aux[i].codigo.concat("/");
str2=str2.concat(aux[i].tipo);
str2=str2.concat("/");
str2=str2.concat(aux[i].nombre);
str2=str2.concat("/");
str2=str2.concat(aux[i].cantidad);

FileWriter fw2= new FileWriter("stock.dat",true);
BufferedWriter bw2 = new BufferedWriter(fw2);
PrintWriter salida2=new PrintWriter(bw2);
salida.println(str2);

}*/

}



}

class herramienta{
private String tipo, codigo, responsable, cantidad;


public int registra_prestamo(String cod, String tip, String resp, String cant)throws java.io.IOException,java.io.FileNotFoundException{
FileWriter fw= new FileWriter("prestamo.txt",true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter salida=new PrintWriter(bw);
//BufferedWriter sal=new BufferedWriter(new FileWriter("prestamo.txt", true));
String str=new String();
str=cod.concat("/");
str=str.concat(tip);
str=str.concat("/");
str=str.concat(resp);
str=str.concat("/");
str=str.concat(cant);
int largo=str.length();

salida.println(str);

salida.close();
System.out.println(str);
return 1;
}
}


public class manejaTool{

public static void main(String[] args)throws java.io.IOException,java.io.FileNotFoundException{
stock obj=new stock();
//herramienta obj2=new herramienta();
//herramienta obj3=new herramienta();
//obj2.registra_prestamo("108", "martillo", "david", "2");
//obj2.registra_prestamo("110", "picota", "roberto","4");
String num=new String();
String s="martillo";
obj.elimina_stockHerramienta(s);
//System.out.println(num);
}
}

lo copie todo, pero el error ocurre cuando agrege el if que esta en rojo, antes tenia el if(cod==codigo), pero son objetos de tipo String y necesito compararlos.