Hi all, I am new to JAVA and my primary lenguage is Spanish, so it may be difficult to explain. I was assigned to do a code that would create HTML tables in which you could see three different tables, one for the low price electronic devices, one for the mid price devices and thos eof the highest mount of price. I already did all the code, but when I run the application (I am using jGrasp) the HTML linksare not created in the folder. This is the code:
__________________________________________________ _____________________
__________________________________________________ ____________-
It is supposed to create the tables and I already have in the folder the .txt file. I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at TestClasificador.main(TestClasificador.java:5)
class TestClasificador
{
public static void main( String args[] )
{
String nArcEntrada = args[0] + ".txt",
nMin = args[0] + "_Precios Bajos.html",
nMed = args[0] + "_Precios Medios.html",
nMax = args[0] + "_Precios Altos.html";
Clasificador leeFormClasif = new Clasificador(nArcEntrada, nMin, nMed, nMax);
leeFormClasif.clasifica();
leeFormClasif.cerrar();
}
}
__________________________________________________ _____________________
public class Registro
{
private int numSerie;
private double Precio;
private String Articulo;
private String Especial;
public int getnumSerie() {
return numSerie;
}
public void setnumSerie(int numSerie) {
this.numSerie = numSerie;
}
public double getPrecio() {
return Precio;
}
public void setPrecio(double Precio) {
this.Precio = Precio;
}
public String getArticulo() {
return Articulo;
}
public void setArticulo(String Articulo) {
this.Articulo = Articulo;
}
public String getEspecial() {
return Especial;
}
public void setEspecial(String Especial) {
this.Especial = Especial;
}
public Registro() {
super();
}
public Registro(int numSerie, double Precio, String Articulo, String Especial) {
super();
this.Precio = Precio;
this.numSerie = numSerie;
this.Articulo = Articulo;;
this.Especial = Especial;
}
}
__________________________________________________ ____________-
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Formatter;
public class Clasificador
{
private Scanner lector;
private Formatter aMin, aMed, aMax ;
public Clasificador(String nArcEntrada,String nMin,
String nMed, String nMax){
try
{
File archivo= new File(nArcEntrada);
lector = new Scanner( archivo );
aMin = new Formatter (nMin );
aMed = new Formatter(nMed);
aMax = new Formatter(nMax);
}
catch ( FileNotFoundException archivoNoEncontrado )
{
System.err.println( "Error opening file." );
System.exit( 1 );
}
catch ( SecurityException seguridad )
{
System.err.println(
"Access denied." );
System.exit( 1 );
}
}
public void clasifica()
{
Registro record = new Registro();
iniciaTabla(aMin,"Tabla de precios bajos.");
iniciaTabla(aMed,"Tabla de precios medios.");
iniciaTabla(aMax,"Tabla de precios altos.");
try
{
while ( lector.hasNext() )
{
record.setnumSerie( lector.nextInt() );
record.setArticulo( lector.next() );
record.setPrecio( lector.nextDouble() );
record.setEspecial( lector.next() );
Formatter salida ;
if (0 < record.getPrecio() && record.getPrecio() <= 299.99)
salida = aMin;
else if
( record.getPrecio() <= 699.99)
salida = aMed;
else
salida = aMax;
anadirRegistro(salida, record);
}
System.out.println("Clasificacion completada");
}
catch ( NoSuchElementException elementException )
{
System.err.println( "File Formatted Inappropiate" );
lector.close();
System.exit( 1 );
}
catch ( IllegalStateException stateException )
{
System.err.println( "Error Reading File" );
System.exit( 1 );
}
}
void anadirRegistro(Formatter archivo, Registro registro ){
archivo.format( "<tr><td>%d</td><td>%s </td><td>%.2f </td><td>%s</td></tr> \n",
registro.getnumSerie(),
registro.getArticulo(),
registro.getPrecio(),
registro.getEspecial() );
}
void iniciaTabla(Formatter archivo,String titulo){
archivo.format(
"<table border align =center>"+
"<caption style='font-family:Arial;color:red;font-weight:bold;font-size:medium;'>"+
titulo+
"</caption>"+
"<colgroup>"+
"<col align= right>"+
"<col align= left>"+
"<col align= left>"+
"<col align= right>"+
"</colgroup>"+
"<tr><th>%-10s<th>%-13s<th>%-14s<th>%10s",
"# Numero De Articulo ", "Nombre De Articulo ", "Precio", "Especial");
}
public void cerrar()
{
if ( lector != null )
lector.close();
if ( aMin != null )
aMin.close();
if ( aMed != null )
aMed.close();
if ( aMax != null )
aMax.close();
}
}
It is supposed to create the tables and I already have in the folder the .txt file. I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at TestClasificador.main(TestClasificador.java:5)