Out of Memory - Trying to build JTable with a .RPT file

Discussion in 'Java' started by shawleigh17, Jun 9, 2009.

  1. shawleigh17

    shawleigh17

    Joined:
    Jun 9, 2009
    Messages:
    2
    Hi, I am trying to read data from a .RPT file, and then use that data to populate a JTable. The fields are fixed length, so I tried to read in substrings and add them to the vector data that way, but I got an out of memory exception. I also sometimes get out of bounds exceptions. The file has some empty string within it, so does anyone know how to account for those, too? Anyways, if someone notices something that can help, please let me know!

    Thanks,
    Shawna


    Code:
    import java.io.*;
    import java.util.*;
    
    import javax.swing.table.AbstractTableModel;
    
    public class ImportOSTableModel extends AbstractTableModel
    {
    	protected Vector<String> data;
        protected Vector<String> columnNames;
        protected String datafile;
       
        public ImportOSTableModel(String f)
        {
            datafile = f;
            initVectors();
        }
       
        public void initVectors()
        {
            String aLine = null;
            data = new Vector<String>();
            columnNames = new Vector<String>();
            try
            {
                FileInputStream fin = new FileInputStream(datafile);
                BufferedReader br = new BufferedReader(new InputStreamReader(fin));
                //LineNumberReader lnr = new LineNumberReader(br);
                //extract column names (14 COLUMNS)
                columnNames.addElement("UPC");
                columnNames.addElement("PROD CODE");
                columnNames.addElement("SF");
                columnNames.addElement("PRODUCT DESCRIPTION");
                columnNames.addElement("CASE VEND PACK");
                columnNames.addElement("BEGINNING INVENTORY");
                columnNames.addElement("IND");
                columnNames.addElement("REPLENISH");
                columnNames.addElement("DEPLETE");
                columnNames.addElement("ENDING INVENTORY");
                columnNames.addElement("IND");
                columnNames.addElement("SHORT/(OVER)");
                columnNames.addElement("SDV-VALUE INV-VALUE");
                columnNames.addElement("COMBINED CODES");
                //get Data
                aLine = br.readLine();//to get empty line
                aLine = br.readLine();//to get empty line
                aLine = br.readLine();
                
                
                while(aLine = br.readLine() != null)
                {
                	data.addElement(aLine.substring(0,6).trim());//6 characters long
                    data.addElement(aLine.substring(6,13).trim());//7 characters long
                    data.addElement(aLine.substring(13,16).trim());// 3 characters long
                    data.addElement(aLine.substring(16,48).trim());//32 characters long
                    data.addElement(aLine.substring(48,54).trim());//6 characters long
                    data.addElement(aLine.substring(54,59).trim());//5 characters
                    data.addElement(aLine.substring(59,74).trim());//15 characters
                    data.addElement(aLine.substring(74,78).trim());//4 characters
                    data.addElement(aLine.substring(78,88).trim());//10 characters
                    data.addElement(aLine.substring(88,97).trim());//9 characters
                    data.addElement(aLine.substring(97,107).trim());//10 characters
                    data.addElement(aLine.substring(107,110).trim());//3 characters
                    data.addElement(aLine.substring(110,119).trim());//9 characters
                    data.addElement(aLine.substring(119,129).trim());//10 characters
                }
                br.close();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
       
        public int getColumnCount()
        {
            return columnNames.size();
        }
       
        public int getRowCount()
        {
            return data.size()/getColumnCount();
        }
    
        public String getColumnName(int columnIndex)
        {
            String colName = "";
            if (columnIndex <= getColumnCount())
                colName = (String)columnNames.elementAt(columnIndex);
            return colName;
        }
       
        public Class getColumnClass(int columnIndex)
        {
            return String.class;
        }
       
        public boolean isCellEditable(int rowIndex, int columnIndex)
        {
            return false;
        }
       
        public Object getValueAt(int rowIndex, int columnIndex)
        {
            return (String)data.elementAt((rowIndex*getColumnCount())+ columnIndex);
        }
       
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)
        {
            return;
        }
    }
    
     
    shawleigh17, Jun 9, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGlhbmEgRXN0cmFkYQ==?=

    How can I show rpt's crystal report 7 in ASP .Net

    =?Utf-8?B?RGlhbmEgRXN0cmFkYQ==?=, Oct 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    824
    =?Utf-8?B?RGlhbmEgRXN0cmFkYQ==?=
    Oct 19, 2005
  2. Anuradha

    Cristal Rpt

    Anuradha, Nov 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    470
    Anuradha
    Nov 24, 2005
  3. CowBoi
    Replies:
    2
    Views:
    460
  4. Gregor Horvath

    Interpretation of UnhandledException.rpt

    Gregor Horvath, Jun 6, 2006, in forum: Python
    Replies:
    0
    Views:
    379
    Gregor Horvath
    Jun 6, 2006
  5. Tintin92
    Replies:
    1
    Views:
    1,809
    Andrew Thompson
    Feb 14, 2007
Loading...

Share This Page