Results 1 to 2 of 2
  1. #1
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Object Input Stream EOFException

    Hi all Java wizards,

    So I've decided to write a simple Log program. It uses Object Input/Output Streams. I whipped this quickly, but I am getting this weird EOFException and I cannot figure it out. The compiler doesn't like the line in bold. :confused:
    The actual complains are:
    at java.io.ObjectInputStream$BlockDataInputStream.pee kByte(Unknown Source) <-- the bold line
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)

    I thought that I forgot to close the streams, but I've double checked. They are getting closed after their used.

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.util.HashMap;
    import java.util.Map;
    import javax.swing.*;
    
    public class Logger implements ActionListener{	
    	
    	ObjectInputStream ois = null;
    	@SuppressWarnings("unchecked")
    	public Logger() throws Exception, IOException{
    		
    		JFrame f = new JFrame();
    		
    		JButton add = new JButton("Add");
    		add.addActionListener(this);		
    		ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream("log.dm")));
    		[B]HashMap<String,String> hm = (HashMap<String,String>)ois.readObject();[/B]		
    		String[][] data = new String[hm.keySet().size()][2];
    		
    		int index = 0;
    		
    		for (Map.Entry<String, String> entry : hm.entrySet())
    		{
    		    data[index][0] = entry.getKey();
    		    data[index][1] = entry.getValue();
    		    index++;
    		}		
    		
    		String [] cols = {"Date","Log"};
    		JTable table = new JTable(data,cols);
    		
    		table.setFillsViewportHeight(true);		
    		f.add(table, BorderLayout.CENTER);		
    		f.add(add, BorderLayout.PAGE_END);		
    		f.setLocationRelativeTo(null);
    		f.pack();
    		f.setVisible(true);
    		ois.close();		
    	}
    	public void actionPerformed(ActionEvent e){
    		new Add();
    	}
    
    }
    Thanks.
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  2. #2
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default

    Worked out myself. I feel very stupid by saying this.

    I forgot actually to write HashMap into a file.

    SOLVED
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

Similar Threads

  1. Input stream error
    By Johnny68 in forum New To Java
    Replies: 10
    Last Post: 08-05-2010, 07:20 PM
  2. Stream closed on a ClassLoader input
    By RaistlinMajeren in forum Advanced Java
    Replies: 15
    Last Post: 06-03-2010, 08:18 AM
  3. standard input stream storing to a generic method?
    By vendetta in forum New To Java
    Replies: 3
    Last Post: 01-29-2010, 09:13 PM
  4. Replies: 0
    Last Post: 07-08-2009, 09:10 AM
  5. Replies: 2
    Last Post: 08-07-2007, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •