• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Assignment Help

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason when I try running the following code, I keep getting a NoClassDefFounderror. Can anyone tell me what I may be doing wrong. I've looked at the code and can't figure it out. I am using Textpad to run and compile my work.




/*
Chapter 4: Using Switch and Try Statements
Programmer: Justin Mosley
Date: September 5, 2007
Filename: Mytype.java
Purpose: This program helps beginning Java programmers understand data types.
*/

import java.io.*;
import javax.swing.JOptionPane;

public class Mytype
{
public static void main(String[] args)
{
//Declare variables
String strChoice, strTryString, strTryInt, strTryDouble;
int choice, tryInt;
double tryDouble;
boolean done = false;

//loop while not done
while (!done)
{
try
{
String message = "What's My Type?"+"n\n1) String\n2) integer\n3) double\n\n";
choice = Integer.parseInt(strChoice);

switch(choice)
{
case 1:
System.out.println("You are correct");
break;

case 2:

break;

case 3:

break;

case 4:
done = true;
break;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Please try again.","Error",JOptionPane.INFORMATION_MESSAGE);
}
{
}
}
}}}
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A NoClassDefFoundError is generally not a problem with your Java code. It's a problem with the way in which you are running it. A class that was available when you compiled the program is not available when you run it. Are you using the same classpath in both cases?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the classpath is not set properly. What command are you using to compile and run? Try the following
to compile -
>javac -classpath .;e:\jar1.jar;e:\jar2.jar package\Test.java
to run -
>java -classpath .;e:\jar1.jar;e:\jar2.jar package.Test

-Medha
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code doesn't run even after you get your runtime enviroment working.





StrChoice needs to be initialized, or made a instance variable (put it outside of main declaration


----------------------------------
For your SDK enviroment: if you are suing windows xp go to Windows_key+pause/break, advanced, enviroment variables, system variables section:

in Path you need the absolute pate of your jdk bin directory followed by semicolon (eg -
C:\Program Files\Java\jdk1.6.0_02\bin;

Then, in the ClassPath variable you need a .; Just like that...so it will search the current directory where you run the main method...it's looking for the class file to load and it searches the ../bin directory by default, and yoru class files aren't there, so it doesn't run.
[ September 07, 2007: Message edited by: Michael Raymond Jr. ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!