Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reaching the catch in readOrders();  RSS feed

 
Pete Berardi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me why its reaching the catch in the readOrders();? There are some commented out lines cuz i tried just about everything. I dont have to read the file to a vector. All i have to do is read the file to something and print it. Can someone help me out here?


 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most useful thing you could do at this point is insert a call to e.printStackTrace() inside each of those catch blocks. Exceptions often contain valuable information about what went wrong, and where.
 
Pete Berardi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stack trace

java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2552)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at OrderHistory.readOrders(OrderHistory.java:268)
at MenuGUI2.readOrdersActionPerformed(MenuGUI2.java:206)
at MenuGUI2.access$1100(MenuGUI2.java:11)
at MenuGUI2$12.actionPerformed(MenuGUI2.java:122)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:177)
at java.awt.Dialog$1.run(Dialog.java:1039)
at java.awt.Dialog$3.run(Dialog.java:1091)
at java.security.AccessController.doPrivileged(Native Method) at java.awt.Dialog.show(Dialog.java:1089)
at java.awt.Component.show(Component.java:1419)
at java.awt.Component.setVisible(Component.java:1372)
at java.awt.Window.setVisible(Window.java:801)
at java.awt.Dialog.setVisible(Dialog.java:979)
at MenuGUI2$13.run(MenuGUI2.java:326)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single, unpronounceable string doesn't work. You can change your display name here. Thanks!
 
Pete Berardi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, is my name real sounding enough to continue?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup!

OK, so now you can look up EOFExceptionin the API, and find out it indicates an end of file or end of stream during input. Input for what? Well, looking at the stack trace, starting at the top and looking for the first method that's in code you wrote, it looks like the exception occurred during a call to readObject(). All right, you tried to read an object from the file, and came to the end of the file before reading the complete object. That could mean the object was incomplete, or perhaps it was not in the file at all.

To me this suggests three possibilities: (1) readObject() was called either before or while an object was written to the file, (2) the object was never written to the file at all, or (3) an error occurred during the writing of the file. I note that right now, the code to write a file would not work, because the variable out is null, and you've commented out all the code that might set it to something else. So my recommendation is: delete any existing allOrders.dat file, then run the program again. Write an allOrders.dat file, and check to make sure no errors occurred during this process. Then try reading the file, and see if it works, or if you get a different error.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!