新Java程序员在尝试运行Java程序时经常会遇到这些消息.
Error: Main method not found in class MyClass, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Run Code Online (Sandbox Code Playgroud)
Error: Main method is not static in class MyClass, please define the main method as:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
Error: Main method must return a value of type void in class MyClass, please
define the main method as:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
java.lang.NoSuchMethodError: main
Exception in thread "main"
Run Code Online (Sandbox Code Playgroud)
这是什么意思,什么可以导致它,以及应该怎么做才能解决它?
我需要帮助主方法,我收到此错误:
Error: Main method not found in class Calculate, please define the main method as:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
这是代码:
class Calculate {
private double fn;
private double sn;
private char op;
public void setNumber(double fnum, double snum){
this.fn = fnum;
this.sn = snum;
}
public double getNumber1(){
return fn;
}
public double getNumber2(){
return sn;
}
public void setOper(char oper){
this.op = oper;
}
public char getOper(){
return op;
}
public void getAnswer(){
double ans;
switch (getOper()){
case …Run Code Online (Sandbox Code Playgroud) 我最近把我的所有代码都手动导入到BlueJ的eclipse项目中,然后我开始使用设置"运行配置",最后认为我是免费的.然后我运行了代码,我收到了这个错误
java.lang.NoSuchMethodError: main
Exception in thread "main"
Run Code Online (Sandbox Code Playgroud)
所以我想我必须添加一个主方法(我从来没有在BlueJ中这样做,为什么?).所以我这样做只是调用了构造函数方法(在BlueJ中我只是创建一个新对象,JFrame会显示).所以我这样做了,同样的错误.尝试不同的事情后(例如将构造函数中的代码移动到不同的方法等).我把它放在主要方法中:
public void main(String[] args)
{
System.out.println("Hello, this is main why won't Java find this.");
}
Run Code Online (Sandbox Code Playgroud)
之后我仍然遇到了同样的错误,所以我决定将它添加到我的所有类中,以确保它没有使用另一个类作为主类.仍然是同样的错误,所以我想知道你是否有人遇到过这个问题.我也搜索了谷歌,我发现的所有问题都是private类等问题,而且感觉我所有的课程都是public(嘿,我来自Python :)).我知道那不是问题.请帮忙 :)
我的运行配置的图片

警告:长
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class AppFrame extends JFrame
{
public String status = "Status:";// Status of Applet
public int paint_count = 1;// Number of times applet has been painted
public int[] mousePos = {-1, -1};// Stores Mouse's Last Clicked X and Y Cordinates
public …Run Code Online (Sandbox Code Playgroud) 这只是一个命名惯例?为什么在从shell执行程序时不能调用任何方法,例如
$> java myPackage.MyClass.myOwnEntryPoint(String[] str)
有人可以帮助我使用下面的代码构建没有任何错误,但当我运行它我得到"错误:在类程序中找不到主要方法,请将主方法定义为:public static void main(String [] args)" ...
任何想法为什么?
import java.util.*;
public class Program
{
// Create an array/database for 100 prizes We can increase this number
private Prize[] prizeDatabase = new Prize[100];
// variable to store the next available position in the database
private int currentArrayPosition = 0;
/**
This method displays the menu to the user
*/
private void DisplayMenu()
{
System.out.println("Please select an option from the following:");
System.out.println("1. Enter details of a prize");
System.out.println("2. Print the details stored …Run Code Online (Sandbox Code Playgroud) 我只是重新阅读我的讲座脚本并在那里试用代码.问题是教授只给了我们代码片段,我真的坚持这个.我在Eclipse中不断收到此错误:
没有主要方法
即使我public static void main(String[] args)输入代码,我仍然会收到错误.我应该改变什么呢?
该程序的主要思想是计算平方根或平方根.
public class MeineKlasse {
private String job;
private String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
System.out.println(job);
}
public double myMethode(double x) throws Exception {
if (job.equals("quadrat"))
return x * x;
if (job.equals("wurzel"))
return Math.sqrt(x);
System.out.println(myMethode(x) + "=");
throw new Exception("Fehler:Aufgabe nicht korrekt definiert");
}
}
Run Code Online (Sandbox Code Playgroud)