java - 没有找到主要类

标签 java class methods

我的项目中只有几个类。主类应该是 SMSMain。但是当我运行该项目时,它给出了没有找到主类的错误。我尝试在属性(Netbeans)中进行设置,但没有找到任何内容。我哪里出错了?这是我的代码:

package 
na.edu.pon.oop210s.s12012.s211045888.sms;
/**
 * Student Number: <211045888>
 * Date: 3/11/12 7:47 pM
 * Exercise: <Exercise 4>
 * Created using: <netbeans>
 */


 public class sms {

 class Student 
{
    int   studentID;
    String studentName,course;

public  void        setName(String studentName){
this.studentName = studentName;
}
public  void        setNewId(int studentID){
this.studentID = studentID;
}

public  void        setCourse(String course){
 this.course = course;
}
public  String      toString(){
return studentID +" "+studentName.toString();

}
    class lecturer{
        int staffID;
        String staffName,taughtCourses;

        public  void        setName(String staffName){
this.staffName = staffName;
}
public  void        setNewId(int staffID){
this.staffID = staffID;
                 }
public  String      toString(){
return staffID +" "+staffName.toString();

}
        class course{
            String code,description;
            double units;

course(String code, String CD){
this.code=code.toUpperCase();
description=CD.toUpperCase();
}
public String getCode(){
return code;

                       }


/**
 * @param args the command line arguments
 */
public class SMSMain {
public  void main(String[] args) {
    // TODO code application logic here
    Student a = new Student();
    a.studentName = "Maria";
    a.studentID = 1236;
    System.out.println("Student Name:" + a.studentName);
    System.out.println("Student Name:" + a.studentID);

 }
}



        }}}}

最佳答案

您需要使用

public static void main(String[] args){/* ... */}

使用static关键字。

另外,将您的 SMSMain 类放入它自己的文件 SMSMain.java 中。然后导入所需的类(在 Eclipse 中按 ctrl-shift-o)。

尝试始终将类放入其自己的文件中,除非您有充分的理由不这样做。

关于java - 没有找到主要类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9758985/

相关文章:

java在方法中返回数组

java - 如何在主类的数组中添加随机构造函数类的值?

java - 将 Delphi App 迁移到 Java 或 Web App

python - 更新多个属性python

javascript - 用 JavaScript 编写,无法正确应用函数?

c++ - 为什么 & 号在 `std::is_member_function_pointer` 中?

java - 从 JAVA 应用程序启动经过摘要验证的网页

java - 在java代码中创建隐藏文件夹

c++ - 在类成员中调用函数 (C++)

c++ - 试图传入另一个类的枚举