Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

My code runs in Eclipse but not in the command line

Posted on 2008-10-14
9
Medium Priority
?
807 Views
Last Modified: 2010-05-18
Hell Experts:
I am new to Java and using Eclipse. My code compiles, runs adequately in Eclipse. When I wanted to test it in regular command lie it compiles but does not run.It runs javac command with no issues (javac Elevator.java) , once I go to run the code (java Elevator) I get this message:
Exception in thread "main" java.lang.NoClassDefFoundError: Elevator

here is a snippet of the code:
package cscie160.hw1;

public class Elevator{
      
      //Declare all constants: capacity of the elevator,
      //and the number of the floors
      static final int NUM_OF_FLOORS = 7;
      static final int ELEVATOR_CAPAITY = 10;
      
      //the elevator is going up
      private final static int goingUp = 1;
      //the elevator is going down
      private final static int goingdown = -1;
      //Data members we need
      
      //Where the Elevator is right now
      private int currentFloor;
      //Where is the Elevator heading
      private int elevatorDirection;
      //destined floor, that is where the elevator is destined per passenger request
      private boolean[] destinedFloorRequest;
      //The number of passengers destined for each floor
      private int[]

numPassengersDestinedForEachFloor;
            //The total number of passengers

in the elevator at any given time
      private int totalNumberOfPassenger;
      
      /**
       * creates a new <code>Elevator</code>

object
       */
.
.
.

 in User variable
 CLASSPATH C:\Program Files\Java\jdk1.5.0_16\bin;C:\Program Files\Java\jre1.6.0_07\bin

JAVA_HOME C:\Program Files\Java\jdk1.5.0_16


In System Variables I have:
CLASSPATH C:\Program Files\Java\jdk1.5.0_16\bin;C:\Program Files\Java\jre1.6.0_07\bin

path: C:\Program Files\Java\jdk1.5.0_16\bin;%M2%;%JAVA_HOME%\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;C:\Program Files\Diskeeper Corporation\Diskeeper\;C:\Program Files\ThinkPad\ConnectUtilities;C:\Program Files\Common Files\Lenovo;C:\Program Files\Lenovo\Client Security Solution;C:\Program Files\Common Files\Adobe\AGL;C:\subversion\bin;C:\strawberry\c\bin;C:\strawberry\perl\bin;C:\Program Files\QuickTime\QTSystem

I do appreciate some help on this one.

thank you all.
0
Comment
Question by:itnema
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

by:itnema
ID: 22713959
Sorry for the typo, I meant Hello Exerts :-)
0
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22714075
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
Since, it's saved in a directory created by eclipse:

Run Command Prompt (found under All Programs/Accessories in the Start menu).  
Type
C:\> cd \yourdir
This makes C:\yourdir the current directory.
C:\mywork> dir
This displays the directory contents.  You should see HelloWorld.java among the files. Apply
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_16\bin

This tells the system where to find JDK programs.
C:\mywork> javac HelloWorld.java

This runs javac.exe, the compiler.  You should see nothing but the next system prompt...
C:\mywork> dir
javac has created the HelloWorld.class file (Your Eclipse did that before!).  

You should see HelloWorld.java and HelloWorld.class among the files.
C:\mywork> java HelloWorld
This runs the Java interpreter.  You should see the program output:
Hello, World!

If the system cannot find javac, check the set path command.  If javac runs but you get errors, check your Java text.  If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command.  Java is case-sensitive!

To have the path permanent (which you have done but check it again):
Click "Edit" and at the system variables of PATH and append
;C:\Program Files\Java\jdk1.5.0_16\bin

If again fails, check for this:
http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html

Best regards as an expert...
0
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22714084
Sorry for the typo, Best regards as an exert.. :-)
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 1

Accepted Solution

by:
waleed hassan earned 172 total points
ID: 22714873
remove this package line  and try again :


package cscie160.hw1;

Open in new window

0
 
LVL 5

Assisted Solution

by:muktajindal
muktajindal earned 164 total points
ID: 22718032
You may try providing classpath while executing the class as follows :

java -cp <path-to-the-class-file> cscie160.hw1.Elevator
0
 

Assisted Solution

by:murpheous
murpheous earned 164 total points
ID: 22720805
From the command line you have to give the complete class name i.e. cscie160.hw1.Elevator instead of Elevator. So your java command should be:
java cscie160.hw1.Elevator

Also make sure that your classpath variable is setup correctly to pick up this class file. For example if your cscie160 folder is in "C:\classes" folder then "C:\classes" should be in classpath.
0
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22741353
so what is your progress?
0
 
LVL 1

Expert Comment

by:ubuntuguy
ID: 22754939
Is your path variable set up correctly?
http://www.apl.jhu.edu/~hall/java/beginner/settingup.html
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question