无法在终端上运行程序.. [英] unable to run program on terminal..

查看:122
本文介绍了无法在终端上运行程序..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个非常简单的代码来开始学习如何编程。当我进入终端时,我首先进入正确的方向,然后键入javac Calc.java。类和java类都存在于该文件夹中。之后我尝试通过输入java Calc来运行它。但是我得到了这个错误(

I created this very simple code to start learning how to program. When I went onto my terminal I first went into the correct directry, and then typed javac Calc.java. the class and java class are both present in the folder. I tried to run it after that by typing, java Calc. But I got this error (

Exception in thread "main" java.lang.NoSuchMethodError: main) What could I be doing wrong here?

public class Calc {

    public void brown ()
    {
        int a = 0;
        int b = 0;
        a++;
        b--;
        System.out.println(a);
        System.out.println(b);
    }
}

推荐答案

消息很简单:你无法启动没有入口点的应用程序。查看最常用的演示:

The message is simple: you can not start an application that has no entry point. See the most used demo:
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}



你看到了区别吗?这将运行,因为它有一个 public static void main(String [] args) signed method。这样做。当然,您也可以使用其他方法。


Do you see the difference? This will run, since it has a public static void main(String[] args) signed method. Do like this. Of course, you can have other methods too.


这种类型的应用程序需要一个入口点方法main。正如我从您的异常消息中可以理解的那样,它已经丢失了。例如,请使用以下指示:

http://www.cs。 utexas.edu/~mitra/cwinstr.html [ ^ ]。



要了解相关主题,请参阅: http://en.wikipedia.org/wiki/Main_function#Java [ ^ ]。



-SA
This type of application needs an entry point method, "main". As I can understand from your exception message, it is missing. Please, for example, use these directions:
http://www.cs.utexas.edu/~mitra/cwinstr.html[^].

To get some background on the topic, please see: http://en.wikipedia.org/wiki/Main_function#Java[^].

—SA


这篇关于无法在终端上运行程序..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆