problem in java

Status
Not open for further replies.

shivi4

Journeyman
i have jdk1.5

written simple program in java

class Pg1
{
public static void main(String[] args)
{


System.out.println("HI");
}
}


it is compling no problem

but when i run java Pg1

it give a exception java.lang "main" cannot be found

please help
 

Satissh S

Youngling
shivi4 said:
public static void main(String[] args)
It sud be like this brother,
public static void main(String args[] )
Though the compiler doesn't detect it, its a logic error.
In the above line u declare that args is a variable of type string. So it shud be in this format String x[]. Java accepts all variables as String type. So u should explicitly convert other variables to String type b4 execution. :)
 

deathvirus_me

Wise Old Owl
It sud be like this brother,
public static void main(String args[] )
Though the compiler doesn't detect it, its a logic error.

You need to refer more books dude .....both the statements work absolutely fine in java .....

and personally i prefer public static void main(String []args) .....

The only reason u cannot run a file is that u must have not added \bin to the system path ... for example if u've installed java in c:\jdk5 .. then u need to add this to the system path : c:\jdk5\bin ... things should run fine after that ....

But i'd suggest u to download JCreatorLE from here :

*www.jcreator.com/download.php?c=62c17291cf80a42763ec26fe8226cca7

U should be able to easily compile/run programs ....it has a very easy-to-use interface ....

Also if u write a code with a single class then declare the class as public and name the code as the class name .......for now atleast ...

Code:
public class prg{
   public static void main(String []args){
      System.out.println("Hello!");
   }
}
save this as prg.java as i've declared the class public
 

siriusb

Cyborg Agent
Nope, java acepts both way of declaring the main method. The problem is that your compiler has placed the .class file somewhere else while the interpreter is looking somewhere else. If u are using cmd line, then try to include path too. Or u may need to set the classpath. Click here to know how.
 

Satissh S

Youngling
Oops! Helping others is fine but leading them wrong is bad! I regret it!
But im using J2se5 along with JBuilder. :)
 
Status
Not open for further replies.
Top Bottom