Program won't execute methods sequentially (consistently)!
OK, I'm very new to Java (and OOP) and just trying to get a grip of it all. So far so good but just hit this little problem. I myself can't find any errors in the code, and Netbeans compiles it fine without producing any errors.
Basically, my intentions are to output the invalid args errors (if any) followed by the two equations.
Each time I run it, the output is listed randomly, sometimes correctly, sometimes not (like below).
I've re-positioned everything countless times but it's still always random!
Illegal input at argument 2 with input a. Characters only!
The sum of valid passed arguments is 3
Illegal input at argument 4 with input b. Characters only!
The average of the passed arguments is 2.0
BUILD SUCCESSFUL (total time: 0 seconds)
Try changing your System.err.print to System.out.println. It might be something as simple as using different writers is allowing for some weird thread condition.
it is all in where rthe stream is writing- I am assuming that behind the scenes the system.out self closes the stream
where as the .err may not do so without some delay because it is checking to see if there is anywhere else it should write the message too... see this forum's bable about it...
there is some bickering there about who is right and who is not- i tried to find some definitive proc infor for you but the bottom line is keep it consistent... I would use the .err to write to a log method (however you handle error logging) and use system.out to write to the console
Edit: more elaboration of how I *think it might be working...
ok what do you want em to write? "blah"
ok what do you want me to write? "blah"
you want me to write that anywhere else? no
*just my thoughts on the matter though
I am assuming here that there is some delegate in the .err method that handles the command argument and it needs to spit back the process of that argument even if that argument is null
Thank you both for your help, this clears so much up for me.
Interesting how this could happen, a real eye opener.
Such a simple program, yet I must have restructured it about 10 times wondering why the hell it wasn't working. I swore it was logical.
|All times are GMT +1. The time now is 03:26 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.