Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in program

 
Parveen Dalal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I made a program but it shows a error so please give me the solution. thanks in advance.

class Xyz {
public static void main(String args[])
{
try
{
Runtime rt = new Runtime.getRuntime();
Process p = rt.exec("shutdown -s -t 1000");

}
catch(Throwable t)
{
t.printStackTrace();
}
}
}

Error is :
Xyz.java:6: cannot find symbol
symbol : class getRuntime
location: class java.lang.Runtime
Runtime rt = new Runtime.getRuntime();
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime rt = new Runtime.getRuntime();

You can't instantiate Runtime. It should read "Runtime.getRuntime(...)", not "new Runtime.getRuntime(...)".

And if you could instantiate it, it would be "new Runtime()", not "new Runtime".
[ July 28, 2007: Message edited by: Ulf Dittmer ]
 
Parveen Dalal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanxs alot its work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic