在网上找到的一个小小的关机程序~~代码如下~
//////////关机程序1
import java.lang.*;
import stec.sfc.Win32.System;
public class Logoff{
public static void main(String[] args){
try{
System.logoff(true);
}
catch(Exception ex){}
}
}
编译通过~没有问题~~可是一运行就提示错误~~错误提示:Exception in thread "main" java.lang.NoClassDefFoundError: logoff我尝试令一个关机程序
/////////关机程序2
import javax.swing.JOptionPane;
import java.io.IOException;
public class Shutdown
{
public static void main(String[] args)
{
//弹出一个对话框,询问是否关机
int result = JOptionPane.showConfirmDialog(
null,
"Will restart this computer, really?",
"Shutdown",
JOptionPane.YES_NO_OPTION);if(result == JOptionPane.YES_OPTION)
{
//执行关机命令
Runtime run = Runtime.getRuntime();
try
{
Process p = run.exec("shutdown -r");
}
catch(IOException e)
{
e.printStackTrace();
}
}
System.exit(0);
}

编译同样通过~~可是一运行还是提示那个错误~
Exception in thread "main" java.lang.NoClassDefFoundError: Shutdown
请问这是什么错误呢?~我该怎么改?~~~谢谢~~在线等~~~

解决方案 »

  1.   

    System.logoff(true);//System类在java.lang中也有,可能有冲突了吧,把包名一起写上。
      

  2.   

    把System.logoff(true);改成stec.sfc.Win32.System.logoff(true);
      

  3.   

    这个与你的环境变量的设置有关
    我以前也碰到过这样的问题,在系统环境变量里,CLASSPATH中你要添加一个你的工作路径,然后的的JAVA程序放到这个路径目录下,这样就可以解决问题了