Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Help with registry HTML.

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with registry HTML.

    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:


    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)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with registry HTML.

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at TestClasificador.main(TestClasificador.java:5)
    At line 5 the code tries to access the first element in an empty array. Since there is no element at index 0, you get an AIOOBE. Test the length of the array before trying to access any elements in it.

    The program is expecting an argument on the commandline when its execution is started.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with registry HTML.

    I don;t understand, I am supposed to increase the elements int he array or change something in the code in the other classes? In the folder 3 .html archives are supposed to appear and they don't, sorry I speak spanish.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with registry HTML.

    What part don't you understand?
    The args array is empty. There is no element at index 0.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with registry HTML.

    Isn't it args be filled with nMin, nMax, nMed?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with registry HTML.

    No. The args array is passed to the main() method by the java program when it starts execution of the class.
    public static void main( String args[] )
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with registry HTML.

    How can I fix this? It seems kind ilogical, all variables and classes and objects seem fine, everything compiles yet the HTML tables dont appear. In the folder I have the txt file with these elements:

    121 NintendoWii 99.00 Si
    122 SamsungGalaxy 190.00 Si
    123 Television 179.00 Si
    125 HomeTheater 230.00 Si
    126 PlasmaTV 250.00 No
    137 SuperPlasma 300.00 No
    139 Toshiba 400.00 No
    146 NexusFridge 550.00 No
    147 OmegaFridge 600.00 No
    157 NexusOven 650.00 Si
    167 AlieanTablet 700.00 No
    456 MACProPC 1200.00 Si
    678 GamingPC 1300.00 No
    693 BrandFridge 1340.00 Si
    890 AlienwarePC 1400.00 Si
    891 HPEliteDesktop 1450.00 No
    892 SonyBundle 1460.00 Si
    985 XBOXBundle 1470.00 Si
    999 SonyGamingDesktop 1500.00 Si

Similar Threads

  1. Creating Registry Key
    By frozen java in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 29th, 2012, 01:46 AM
  2. Can anyone help with my code please?? (Reading the Registry)
    By mozza in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 9th, 2012, 11:27 AM
  3. Reading the registry
    By mozza in forum Java Theory & Questions
    Replies: 2
    Last Post: January 31st, 2012, 11:33 AM
  4. Java Installation with no Registry Key?
    By ch103 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 20th, 2011, 06:41 PM
  5. JFM Registry error
    By mp3rara in forum AWT / Java Swing
    Replies: 4
    Last Post: April 16th, 2011, 03:51 PM