当前位置: 技术问答>java相关
为什么 总是 Exception in thread "main" java.lang.NoClassDefFoundError: NewsRobot/class????
来源: 互联网 发布时间:2015-06-09
本文导语: 我的 程序 代码如下,为什么 总是 Exception in thread "main" java.lang.NoClassDefFoundError: NewsRobot/class???? (程序要实现的功能是定期 执行 一段代码) why? public class Robot extends Thread{ private long interval = 60000*60*1...
我的 程序 代码如下,为什么 总是 Exception in thread "main" java.lang.NoClassDefFoundError: NewsRobot/class????
(程序要实现的功能是定期 执行 一段代码) why?
public class Robot extends Thread{
private long interval = 60000*60*12; //12Сʱ
public Robot(){
}
public Robot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
action();
}
} catch (Exception e){}
}
public void action(){
System.out.println("-----------------");
}
}
public class NewsRobot {
public static void main (String arg[]){
Robot newsRobot = new Robot(1000);
newsRobot.start();
}
}
(程序要实现的功能是定期 执行 一段代码) why?
public class Robot extends Thread{
private long interval = 60000*60*12; //12Сʱ
public Robot(){
}
public Robot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
action();
}
} catch (Exception e){}
}
public void action(){
System.out.println("-----------------");
}
}
public class NewsRobot {
public static void main (String arg[]){
Robot newsRobot = new Robot(1000);
newsRobot.start();
}
}
|
你的程序改成如下:
public class Robot extends Thread{
private long interval = 60000*60*12; //12Сʱ
public Robot(){
}
public Robot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
action();
}
} catch (Exception e){}
}
public void action(){
System.out.println("-----------------");
}
public static void main (String arg[]){
Robot newsRobot = new Robot(1000);
newsRobot.start();
}
}
没问题,已经测试过了:)
public class Robot extends Thread{
private long interval = 60000*60*12; //12Сʱ
public Robot(){
}
public Robot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
action();
}
} catch (Exception e){}
}
public void action(){
System.out.println("-----------------");
}
public static void main (String arg[]){
Robot newsRobot = new Robot(1000);
newsRobot.start();
}
}
没问题,已经测试过了:)
|
把目前目录加到CLASSPATH上
c:YourDirectory>set classpath=.;%classpath%
c:YourDirectory>java NewsRobot
c:YourDirectory>set classpath=.;%classpath%
c:YourDirectory>java NewsRobot