|
| |
Magnaillusion CM
|
[Java]Program doesn't run |
|
I've been reading Java in a Nutshell, 5th edition, to learn the basics of Java and OOP. It happens that at the first few pages, we were told to write a practice program and run it. After struggling with the javac a little, I found a software, jGRASP, that would compile and run the code for me. The catch, is, the program compiles, but it doesn't run for some reason. The code is:
And the error message is: After it spews out that error, no more interactions are allowed to me. If anybody could help with this issue, it would be pretty much appreciated. ------------------- ![]() | |
quote quick quote edit quick edit del posts in thread report
| |
Mr Roboto
|
re: [Java]Program doesn't run |
|
Are you passing it any args? Looks like the args array is empty, and when you try to do args[0], it throws that exception. Also, what problems were you having when trying to compile at the command line?
------------------- | |
quote quick quote edit quick edit del posts in thread report
| |
Magnaillusion CM
|
re: [Java]Program doesn't run |
|
I copied the code from the book as it was, also, it is the first time I built, compiled and ran a Java program, so I wouldn't know any problems or special conditions I had to fulfill. I really don't know how to pass args on jGRASP.
About the command line, it doesn't recognizes javac "as an internal or external command, program or executable". I tried Googling a solution, and I copied a couple of lines on the autoexec.bat, but to no avail. Mag's Edit: I tried defining the incoming argument with value of 4. It seems that the program runs well; it is the way of running the program that brings it down. ------------------- ![]() | |
quote quick quote edit quick edit del posts in thread report
| |
Mr Roboto
|
re: [Java]Program doesn't run |
|
Yeah, your program was expecting input. When you run your program, you can pass it arguments. eg java Factorial 4 would put 4 in the String[] args array passed into Main. If you did java Factorial 1 3 5, your array would have three values in it.
I'm guessing you don't have your PATH variable setup properly, so the command prompt doesn't know where to look when you type javac. Instructions for that can be found here. You'd need to add the path to wherever you installed the JDK. Something like C:\JDK6\bin. You can also point directly to where you installed it if you don't want to setup your PATH. Assuming you installed the JDK at C:\JDK6, you could enter at the command prompt - > c:\JDK6\bin\javac Factorial.java ------------------- | |
quote quick quote edit quick edit del posts in thread report
| |
Magnaillusion CM
|
re: [Java]Program doesn't run |
|
Perfect; thank you Mr. Roboto, now the javac command runs perfectly, compiles and runs the program without problems. As expected from the book, the code worked as it should have. Thanks again for your help on this issue.
------------------- ![]() | |
quote quick quote edit quick edit del posts in thread report
| |
tom111
|
re: [Java]Program doesn't run |
|
Cool, someone at the same level as me in Java. It's nice to know I'm not the only newbie.
------------------- BSc Computer Science student @ Staffordshire University
| |
quote quick quote edit quick edit del posts in thread report
| |
| [All dates in (PT) time] | Threads List « Next Newest Next Oldest » |
Powered by neoforums v0.9.8b (equilibrium)
Copyright Neo Era Media, Inc. 1999-2009