This content has been marked as final. Show 7 replies
"Could not find the main class" is what you get when you have not specified the main class properly.
"Program wil exit..." looks like a message from an IDE (a program source editor). This is really bad news as it suggests you may not conscious of how you are specifying the main class.
Ignoring the IDE for the moment, the code you posted should be in a file called:
BouncingBall.javaAnd that file must be in a directory called the same as its package:
BouncingBallThis package can be anywhere on your disk. In what follows I'll assume it is in c:\java\ First correct your program - because it won't compile at the moment - by adding a } missing at the end. Then:
C:\>cd \javaWhat these steps do is
C:\java>javac -cp . BouncingBall\BouncingBall.java
C:\java>java -cp . BouncingBall.BouncingBall
* Navigate to the working directory
* Compile the source file (specified by its filename) using the current directory as the classpath (that's what -cp . is all about)
* Runs the main class (specified by its full class name)
If you get stuck, elaborate those commands with a few more which give diagnostic information:
C:\>cd \javaCopy and post the actual output. Remember that these examples assume hat you are working from a directory called "java". If you are using Linux and can't translate the commands, say.
C:\java\>javac -cp . BouncingBall\BouncingBall.java
C:\java\>java -cp . BouncingBall.BouncingBall
A few points:
(1) It would be much better to call the package bouncingBall, not BouncingBall. Using small letters at the start of package names is a convention. Both the .java source file and the directory name need to be changed.
(2) You have written no code to make your program exit. From the Windows command line you can make it exit by typing Control+C
(3) The stuff you do with the Graphics object looks a little odd. You might want to have a look at Sun's Tutorial section on Graphical User Interfaces (http://java.sun.com/docs/books/tutorial/ui/index.html) or other bits of the Tutorial (http://java.sun.com/docs/books/tutorial/index.html)
Sorry. I post it incorrectly. However, the one with correct braces didn't work out . I used Eclipse to write , so I didn't really have command-lines involving javac. The only thing about the classpath I find so far is a file named .classpath with the content posted below.
"<?xml version="1.0" encoding="UTF-8"?>
<classpathentry path="" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="" kind="output"/>
I still don't know how to fix the problem.But thanks for you help.
I think he just needed a simple run, not running from jar file.
Simple example of compilation and running of java classes with java package used. With the use of java package, it is a bit different. Below is just an example. Run it from the "Root" of the directory.
To compile from command line:
If above java compilation completed successfully, run from command line:
Hope it helps.