×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Not all Java classes can be run as an application

If we issue a command like

java Hello

it implies we take it as an Java Application. It should have a main(String args[]) method as
an entry point. The code you mentioned, I guess because I don't have a copy of Thinking in Java, has No main() methods.
So this you cannot run it by issuing a command like


java AllOps

If you do that, JVM will examine the byte-code. Once it goes throught the byte-code and does not foind main() method, it throws the error you cited here.

Jabber bets!

godd luck.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Jabber, when I read ThinkingInjava, I run a programme named AllOps.java. First, I compiled it successfully, afterwards, I run it, but error "Exception in thread 'main'...". Why?
    • Post your complet error message here, please.
    • Exception in thread "main" java.lang.NoSuchMethodError: main.
      • Not all Java classes can be run as an application
        If we issue a command like

        java Hello

        it implies we take it as an Java Application. It should have a main(String args[]) method as
        an entry point. The code you mentioned, I guess because I don't have a copy of Thinking in Java, has No main() methods.
        So this you cannot run it by issuing a command like


        java AllOps

        If you do that, JVM will examine the byte-code. Once it goes throught the byte-code and does not foind main() method, it throws the error you cited here.

        Jabber bets!

        godd luck.
      • I guess that. Thanks. I feel a bit difficult in reading ThinkingInJAVA. Jabber, you're a good teacher and warm-hearted person. The beginners as me need your help. Don't care about the impolite words.
        • That book is a great one.
          Also I admit that it's challenge to read it. For people without coding experience in other language like C, it takes some more time to read it.

          You don't have to finish every section and every line, but for some basic ones you'd better study it thoroughly, and compile the examples by yourself. Try to do some modification to those examples and see what happens.
        • Thanks,Sailor. Do want you say.
          I read 4 chapters in one week. Now, I feel so conflicting about all concepts. I try to compile the examples. After doing 10 programs, I find I have less impression about them. Changing method may be my solution. As I have been not coded for 5 yrs, it's a great challenge for me.
        • Cora, thanks for flattering...
          If you get stuck with some parts of the book., you may jump to other parts. The most important thing is to write small programms to test the principles you have learnt.

          Since you were a programmer, it is not too difficult for you to pick up Java.