Exception in thread "main" java.lang.NoSuchMethodError: main - how can I fix that? [duplicate]
Possible Duplicate:
Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”'
I am using Eclipse. I deleted everything and left the main function - nothing is working. Can somebody pls help?
package good;
import java.io.*;
public class FiF开发者_高级运维o {
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();
}
}
}
The main function should have a signature like:
public static void main( String[] args )
{
// stuff ...
}
You've missed out the String array. When you run the program it expects to find a method with this signature, not the empty arg list you have in your sample code.
from the java docs:
Exception in thread "main" java.lang.NoSuchMethodError: main
The Java VM requires that the class you execute with it have a main method at which to begin execution of your application.
so it's probably the wrong main signature, as stated in the first post
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());
}
}
}
public static void main() // not correct signature for main
If you're using Eclipse, you need to make sure that you "Run As" a "Java Application".
精彩评论