help in java program

Status
Not open for further replies.

shivi4

Journeyman
Joined
Oct 4, 2004
Messages
162
i wrote a program in java

it is complilng ok,but it is giving error runtime in dos prompt

H:\shivi>java Pg2
Exception in thread "main" java.lang.NoClassDefFoundError: Pg2


this is the program
public class Pg2
{
public static void main(String[] args)
{
int m=1,i;
while(m<=5)
{
i=1;
while(i<=m)
{
System.out.print(" "+i);
i++;

}
System.out.println("");
m++;
}

}
}

but when in run the program in idelike dr java it is not giving any error
 

QwertyManiac

Commander in Chief
Joined
Jul 17, 2005
Messages
6,575
Well, this happens to me also sometimes but not after i change something in the code.
try removing the public b'fore the class coz u dont need it in this program (not really necessary).

Also if the problem persists plz try to do a re-install of the SDK.

It happens rarely to me but i dont know what the problem exactly is coz the code is ok.

Even for me in Eclipse i get no errors.
 

aadipa

Padawan
Joined
Feb 12, 2004
Messages
990
1. Check your CLASSPATH environmental variable. You must set it to current directory. Try this command
Code:
SET CLASSPATH=.;%CLASSPATH%

2. I feel stupid to ask this, but did u first compiled the program using javac ?
 
Status
Not open for further replies.
Top