• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Unable to run java program


My lecturer has given us a sample java program which consists of three java files.
1) Create.java
2) Record.java
3) Enrol.java

As instructed by her, we have to do the following steps:
Compile Record.java
Compile Create.java
Run Create.java
Run Entrol.java

However, I encountered errors when running Enrol.java. Can someone please help? I would very much like to seek help from her but as my course is a part-time basis, the earliest date i can see her is next week.

Please advise. The sample files are found at http://test.swenlee.com/java.html
1 Solution
Could you paste the exception that are you getting?
Gibu GeorgeCTOCommented:
Is it giving NoClassDefFound?, then set the classpath to ccurrent directory

java -cp . Create
java -cp . Enrol
i suppose, the instructions must be:
Compile Record.java
Compile Create.java
!  Compile Enrol.java
Run Create.java
Run Enrol.java
This is what you need to do :

Copy all the java files and put them in a single directory (leave thenm if they already are)

Open command prompt and go to the directory - at the prompt, do this

javac *.java

---This will result in all the class files being generated

--Now to run Create

java -classpath . Create

-- To run Enrol

java -classpath . Enrol

See the '.' in the command - its for setting the classpath to current directory so that java knows where to pick up the class files from.
dandeliondreamAuthor Commented:
Thanks arioh for your comments. It works now!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now