Exception in thread "main" java.lang.NoSuchMethodError: main - how can I fix this?

Possible duplicate:
Reasons 'java.lang.NoSuchMethodError: main Exception in thread' main ''

I am using Eclipse. I deleted everything and left the main function - nothing works. Can anyone help?

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(); } } } 
+4
source share
5 answers

The main function should have a signature like:

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

You missed the String array. When you run the program, it expects to find a method with this signature , and not the empty list of arguments that you have in your sample code.

+9
source
 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()); } } } 
+1
source

from java docs:

Exception in thread "main" java.lang.NoSuchMethodError: main

Java VM requires that the class you execute with it the main method for which the application.

so this is probably the wrong main signature, as indicated in the first post

0
source
  public static void main() // not correct signature for main 
0
source

If you use Eclipse, you need to make sure that you "Run as" a Java application.

0
source

Source: https://habr.com/ru/post/1300685/


All Articles