首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse中出错-找不到Mainclass

Eclipse中出错-找不到Mainclass
EN

Stack Overflow用户
提问于 2014-02-01 18:14:36
回答 5查看 2K关注 0票数 1

我是编程新手,我非常喜欢它。我刚刚下载了Eclipse,我得到了一个错误,我不能帮助我。不幸的是,它是用德语写的,但它的意思类似于:“没有找到主类”-- "Fehler: Hauptklasse konnte nicht gefunden oder geladen werden“

我知道这跟"public static void main(String [] args)“有关。由于这是一个全新的事实,这将是一个很酷的你可以帮助我。

下面是错误源代码;

代码语言:javascript
复制
/**
 * Write a description of class Light here.
 * 
 * @author (Sunny)
 * @version (31.01.2014)
 */

public class Elevator {
    // Variables

    int maxCarr; // max. carry in KG
    int currentCarr; // current state of carry measured in people
    boolean fillCondition; // filed or empty - value false = empty
    int currentStage; // stage where elevator remains


    // Constructor
    public Elevator() // initiation
    {
        maxCarr = 1600;
        currentCarr = 0;
        fillCondition = false;
        currentStage = 0;
        System.out.println("**********");
        System.out.println("*        *");
        System.out.println("*        *");
        System.out.println("*        *");
        System.out.println("*        *");
        System.out.println("*        *");
        System.out.println("*        *");
        System.out.println("**********");
    }

    public int  (int carry) // Setting carry into the elevator
    {
        currentCarr = carry;
        if (currentCarr != 0) {
            fillCondition = true;
            return 1;
        } else {
            return 0;
        }
    }

    public void move(int stage) {
        if (stage > currentStage) {
            System.out.println("moving up");
            currentStage = stage;
        } else {
            System.out.println("moving down");
            currentStage = stage;
        }
    }
}
EN

回答 5

Stack Overflow用户

发布于 2014-02-01 18:21:41

当你运行java时,它运行的是我在你的类中看不到的main方法,所以基本上eclipse是在告诉你:“你想让我运行什么?”,你应该实现它:

代码语言:javascript
复制
public static void main(String[] args){
    // code here
}
票数 2
EN

Stack Overflow用户

发布于 2014-02-01 18:28:09

我发现了另一个错误。

代码语言:javascript
复制
  public int  (int carry) // Setting carry into the elevator
{
    currentCarr = carry;
    if (currentCarr != 0) {
        fillCondition = true;
        return 1;
    } else {
        return 0;
    }
}

方法不能调用int‘。此名称由Java语言保留。

票数 2
EN

Stack Overflow用户

发布于 2014-02-01 18:28:36

在开发核心java应用程序时,您所需要做的就是在其中包含一个JVM 方法(当然,该方法的功能是:P),它是您试图运行应用程序时搜索的第一个代码片段。对于上面的代码,请尝试如下所示:

代码语言:javascript
复制
public static void main (String [] args) {

//Now, make an instance of your class to instantiate it.

Elevator obj = new Elevator();

//Then,as per the desired functionality. Call the methods in your class using the reference.

//obj.move(val of stage);

obj.move(10);
}

只要确保有一个用于执行java代码的main方法即可。快乐编码:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21496738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档