可能重复:
Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”'
我正在使用Eclipse。我删除了所有内容并离开了主要功能 - 没有任何工作。有人可以帮忙吗?
package good;
import java.io.*;
public class FiFo {
public static void main()
{
System.out.println("here");
}
}
class FileReader {
public FileReader(String fileName)
{
try {
FileInputStream fstream = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:9)
主要功能应该有如下签名:
public static void main( String[] args )
{
// stuff ...
}
你错过了String数组。当你运行程序时,它希望找到a method with this signature,而不是你的示例代码中的空arg列表。
答案 1 :(得分:0)
来自java docs:
线程“main”中的异常 java.lang.NoSuchMethodError:main
Java VM需要该类 你执行它有一个主方法 开始执行你的 应用
所以它可能是错误的主要签名,如第一篇文章所述
答案 2 :(得分:0)
import java.util.*;
import java.io.*;
import java.lang.*;
public class Run
{
static BufferedReader nhap = new BufferedReader(new InputStreamReader(System.in));
public Run()
{
}
public static void main(String[] args) throws Exception
{
int chon;
System.out.println("1. Nhap Sinh Vien");
System.out.println("2. Nhap Giao Vien");
System.out.println("=> Moi ban chon 1 hoac 2 de nhap lieu");
chon = Integer.parseInt(nhap.readLine());
switch (chon)
{
case 1:
{
System.out.print("So luong sinh vien can nhap vao: ");
int SoSV = Integer.parseInt(nhap.readLine());
System.out.print("=> Test : " + SoSV );
SinhVien[] SV = new SinhVien[SoSV];
int i;
for (i = 0; i < SV.length; i++);
{
System.out.printf("Nhap thong tin Sinh vien thu %d \n ", i + 1);
SV[i] = new SinhVien();
AddSV(SV[i]);
}
}
case 2:
{
}
default: System.out.println("Lua chon cua ban khong co trong danh sach !");
}
}
public static void AddGV(GiaoVien gv) throws Exception
{
try
{
System.out.println("Nhap ma Giao vien: ");
int ma = Integer.parseInt(nhap.readLine());
System.out.print("Nhap ho ten giao vien ");
gv.setHoten(nhap.readLine());
System.out.print("Nhap tuoi giao vien");
int tuoi = Integer.parseInt(nhap.readLine());
System.out.print("Nhap ten khoa giao vien dang day");
gv.setTenKhoa(nhap.readLine());
System.out.print("Nhap chuyen nganh giao vien day");
gv.setChuyenNganh(nhap.readLine());
System.out.print("Nhap vao Mon giao vien day");
gv.setMonDay(nhap.readLine());
}
catch(Exception ex)
{
throw new Exception (ex.getMessage());
}
}
public static void AddSV(SinhVien sv) throws Exception
{
try
{
System.out.println("Nhap ma Sinh vien: ");
int ma = Integer.parseInt(nhap.readLine());
System.out.print("Nhap ho ten Sinh vien ");
sv.setHoten(nhap.readLine());
System.out.print("Nhap tuoi Sinh vien ");
int tuoi = Integer.parseInt(nhap.readLine());
System.out.print("Nhap ten khoa Sinh vien dang hoc");
sv.setTenKhoa(nhap.readLine());
System.out.print("Nhap Khoa sinh vien dang hoc");
sv.setKhoaHoc(nhap.readLine());
System.out.print("Nhap vao Lop Sinh vien hoc");
sv.setLop(nhap.readLine());
}
catch(Exception ex)
{
throw new Exception (ex.getMessage());
}
}
public static void OutPutSV(SinhVien sv) throws Exception
{
try
{
sv.Tostring();
}
catch(Exception ex)
{
throw new Exception(ex.getMessage());
}
}
public static void OutPuttGV(GiaoVien gv) throws Exception
{
try
{
gv.Tostring();
}
catch(Exception ex)
{
throw new Exception (ex.getMessage());
}
}
}
答案 3 :(得分:-1)
public static void main() // not correct signature for main
答案 4 :(得分:-1)
如果您正在使用Eclipse,则需要确保“Run As”为“Java Application”。