wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes command line goes nuts! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "command line goes nuts!" Watch "command line goes nuts!" New topic
Author

command line goes nuts!

J Chandler
Ranch Hand

Joined: May 17, 2003
Posts: 32
Hey guys,

I'm coming to the final stages of an application I'm working on.
A similar design to SCJD exam format i.e. db tier, networking tier and GUI tier.

All methods in database tier are called from GUI tier via a controller object. All the methods for displaying data work fine, but I'm having trouble with a method that modifies the data.

When I run the program, the command line goes nuts, outputting so fast I can't read it! (you know, like when you put System.out.println(......) in an infinite loop).

I have to close everything and start over - the curious thing is that when I start the program again, the changes in the data have taken effect so the method worked.

Sometimes when I start over, an exception is thrown because it tries to find the db files and returns null! (I thought of serialVersionUID, but the structures of the classes that implement serializable haven't changed)

Does anyone know of a reason why the command prompt would react like this, bearing in mind that there are NO LOOPS in that part. (all output is logging statements and debugging stuff)

Regards,
J
[ August 11, 2004: Message edited by: J Chandler ]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Recursion?

Surely the clue would be in what is printed. Have you tried redirecting stdout and/or stderr to a file and analysing the rogue output?

Jules
J Chandler
Ranch Hand

Joined: May 17, 2003
Posts: 32
Hey Jules,

recursion - that's when one method calls another, which in turn calls the first and so on, right?

I'll take a look.

Did manage to read the logging output - it's an info statement from a get() in one of the classes that implements Serializable...I'm guessing that's what's corrupting it after it throws a hissy fit.

Cheers for the pointer

J
J Chandler
Ranch Hand

Joined: May 17, 2003
Posts: 32
Woe is me...

it appears I have failed to resolve the above problem

It's not the GUI implementation - command line reacts the same if I modify data right there, on DosPrompt.

I think something mad happens when the persist() method calls a getId()method to form the filepath statement.
This is exactly where the logging info statement prints out over and over.

...and still the file is saved successfully, but in a very messy way.

J has a headache - please make comments you guys - I'll try any ideas
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
OK, firstly what I suggest you do is take a copy of the program and simplify it as much as you can to isolate the source of the error. Once you've done that, if you still can't identify the problem then post the code and I'll see if I can help.

Jules
J Chandler
Ranch Hand

Joined: May 17, 2003
Posts: 32
Jules,



found it!!!

here's where I was going wrong - in my bookCabin(id, dateRequested, guest) method, I was using ListIterator to look through and compare available dates with the date that the user/guest had requested.

I used i.next() for the comparison - if I got a match, I used i.previous() to obtain the value and assign it to a variable, then continue with the booking process.

Main problem was the same value was being compared again and again because the 'pointer' was jumping back and forth over the date we needed to book, booking it over and over. :roll:

Solutions:
assign i.next() to a variable first before the comparison - therefore no need to use i.previous() (but then I may as well have used plain old Iterator instead of ListIterator.

OR

return from the method as soon as the date has been booked instead of letting it iterate through the rest - less cost if the list is long and better programming practice.

I have filed this example under 'Stupid mistakes #527' (chortle)

Jules, thanks for all your help, mate,
Regards,
J
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Thought you said no loops...tsk, tsk!

Well, I'm glad you've got it sorted. Hope my suggestions were of some help.

Jules
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: command line goes nuts!
 
Similar Threads
Questions regarding to using applets and JComponents
GUI based interface for a (already developed)command prompt application
threads for GUI and command-line
Forwarding data changes in MVC
NX: suncertify.properties