Topic: 求教一个执行时的错误!

  Print this page

1.求教一个执行时的错误! Copy to clipboard
Posted by: spxrttn
Posted on: 2007-07-01 16:30

我在JCreator中执行的程序编译没问题,但执行后出现
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
这个错误提示,不知道什么原因,我在dos下能执行!这个问题经常出现,有人说是JDK设置问题,可我检查过了,根本没有问题。请高手赐教,谢谢!
程序代码如下:
abstract class Animal{
  String name;            
  boolean mammal,carnivorous;    
  int mood;            
  Animal(String naMe,boolean maMmal,boolean caRnivorous,int moOd){
    name=naMe;
    mammal=maMmal;
    carnivorous=caRnivorous;
    mood=moOd;
  }
  void isMammal(){
    if (mammal==true){
      System.out.println(name+"is Mammal !");
    }else{
      System.out.println(name+"isn't Mammal !");
    }
  }
  void isCarnivorous(){
    if (carnivorous==true){
      System.out.println(name+"is Carnivorous !");
    }else{
      System.out.println(name+"isn't Carnivorous !");
    }    
  }
  void setMood(int newValue){  
  }
  void getMood(){
  }      
  void sayHello(){
  }
  
}
class Dog extends Animal{        
  int numberOfLegs;        
  Dog(String naMe,boolean maMmal,boolean caRnivorous,int moOd,int legs){
    super(naMe,maMmal,caRnivorous,moOd);
    numberOfLegs=legs;
    this.isMammal();
    this.isCarnivorous();
    sayHello();
    sayHello(mood);
    getMood();
    LandAnimal objLand=new LandAnimalImplements();
    objLand.getNumberOfLegs(this.name,numberOfLegs);
    System.out.println();
  }
  void sayHello(){
    System.out.println(name+"Under normal circumstances,And greet people in the form of:Shaking his tail");
  }
  void sayHello(int newValue){
    if (newValue==1){
      System.out.println(name+"Been patted the mood is good,Greeted the way :Wang Wangwang");
    }else if(newValue==0){
      System.out.println(name+"Angry when: Bark");
    }else{
      System.out.println("Emotional input error");
    }
  }
  void getMood(){
    System.out.println(name+"Irritable when : Wuwuwu");
  }
}
class Cat extends Animal{
  int numberOfLegs;
  Cat(String naMe,boolean maMmal,boolean caRnivorous,int moOd,int legs){
    super(naMe,maMmal,caRnivorous,moOd);
    numberOfLegs=legs;
    this.isMammal();
    this.isCarnivorous();
    sayHello();
    sayHello(mood);
    LandAnimal objLand=new LandAnimalImplements();
    objLand.getNumberOfLegs(this.name,numberOfLegs);
    System.out.println();
  }
  void sayHello(){  
    System.out.println(name+"Under normal circumstances,And greet people in the form of:Meow meow");  
  }
  void sayHello(int newValue){
    if (newValue==1){
      System.out.println(name+"Been patted the mood is good : Grunt grunt call");
    }else if (newValue==0){
      System.out.println(name+"Angry when: Mao gave back");
    }else{
      System.out.println("Emotional input error");
    }
  }
}
class Frog extends Animal{
  int numberOfLegs;
  Frog(String naMe,boolean maMmal,boolean caRnivorous,int moOd,int legs){
    super(naMe,maMmal,caRnivorous,moOd);
    numberOfLegs=legs;
    this.isMammal();
    this.isCarnivorous();
    sayHello();
    sayHello(mood);
    WaterAnimal objWater=new WaterAnimalimplements();
    objWater.hasGills(this.name);
    objWater.laysEggs(this.name);
    LandAnimal objLand=new LandAnimalImplements();
    objLand.getNumberOfLegs(this.name,numberOfLegs);
  }
  void sayHello(){
    System.out.println(name+"Under normal circumstances,Greeted the way : Guaguagu");  
  }
  void sayHello(int newValue){
    if (newValue==1){
      System.out.println(name+"Been patted the mood is good : Guaguagu call");
    }else if (newValue==0){
      System.out.println(name+"Angry when : Escape");
    }else {
      System.out.println("Emotional input error");
    }
  }
}
class Chicken extends Animal{
  int numberOfLegs;
  Chicken(String naMe,boolean maMmal,boolean caRnivorous,int moOd,int legs){
    super(naMe,maMmal,caRnivorous,moOd);
    numberOfLegs=legs;
    this.isMammal();
    this.isCarnivorous();
    sayHello();
    sayHello(mood);
    WaterAnimal objWater=new WaterAnimalimplements();
    objWater.hasGills(this.name);
    objWater.laysEggs(this.name);
    LandAnimal objLand=new LandAnimalImplements();
    objLand.getNumberOfLegs(this.name,numberOfLegs);
  }
  void sayHello(){
    System.out.println(name+"Under normal circumstances,And greet people in the form of : Woo Oh");  
  }
  void sayHello(int newValue){
    if (newValue==1){
      System.out.println(name+"Been patted the mood is good,Greeted the way :Woo Oh Call");
    }else if (newValue==0){
        System.out.println(name+"When the shock when : Ascended to the roof");
    }else {
      System.out.println("Emotional input error");
    }
  }
}
public class AnimalDemo{
  public static void main (String[] args){
    Dog obj01=new Dog("Dog",true,true,1,4);
    Cat obj02=new Cat("Cat",true,true,1,4);
    Frog obj03=new Frog("Frog",false,false,1,4);
    Chicken obj04=new Chicken ("Chicken",false,false,1,2);
  }
}
接口如下2个文件:
public interface WaterAnimal{
  public void hasGills(String name);
  public void laysEggs(String name);
}
public interface LandAnimal{
  public void getNumberOfLegs(String name,int numberOfLegs);
}
接口实现文件:
class LandAnimalImplements implements LandAnimal{
    public void getNumberOfLegs(String name,int numberOfLegs){
      System.out.println(name+""+numberOfLegs+"");
    }
}
class WaterAnimalimplements implements WaterAnimal{
  public void hasGills(String name){
    System.out.println(name+"");
  }
  public void laysEggs(String name){
    System.out.println(name+"");
  }
}
还有1个问题,就是我用中文关闭文件再打开就成乱码了,有没有方法支持中文!

2.Re:求教一个执行时的错误! [Re: spxrttn] Copy to clipboard
Posted by: tkzht0105
Posted on: 2007-07-07 16:52

jdk重新配置一下吧,我这运行一切正常哦

3.Re:求教一个执行时的错误! [Re: spxrttn] Copy to clipboard
Posted by: Cappuccino
Posted on: 2007-07-08 04:00

楼主确定你运行的是AnimalDemo这个类?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923