Results 1 to 19 of 19
  1. #1
    dwilliams is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Default cannot find main - it is there though

    Hi,
    I'm new to java and have run across a problem fairly soon after starting. Here's a bit of code I typed in. When I build the project, it does so with no issues. When I try to run it JCreator tells me it can find no 'main'. I checked everything but can find no fault in the syntax. Difficult language this after VB.
    Any help much appreciated.
    Thanks



    import static java.lang.system.out;
    import static java.lang.system.in;
    import java.util.Scanner;
    import java.util.Random;

    class DTTTL {

    public static void main(String args[]) {
    Scanner myscanner = new Scanner(in);
    out.print("Enter a number between 1 and 10");
    int inputNumber = myscanner.nextInt();

    int randomNumber = new Random.nextInt(10)+ 1;
    if(randomNumber==inputNumber) {
    out.println("*You win*);
    }
    out.println("That was a very good guess :-)");
    out println("The random number was ");
    out println(randomNumber + '.');
    out println("Thanks for playing");

    }
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    My first attempt to compile your code resulted in:
    Java Code:
    C:\jexp>javac DTTTL.java
    DTTTL.java:15: unclosed string literal
                out.println("*You win*);
                            ^
    DTTTL.java:18: ';' expected
            out println("The random number was ");
                       ^
    DTTTL.java:19: ';' expected
            out println(randomNumber + '.');
                       ^
    DTTTL.java:19: not a statement
            out println(randomNumber + '.');
                                     ^
    DTTTL.java:19: ';' expected
            out println(randomNumber + '.');
                                          ^
    DTTTL.java:20: ';' expected
            out println("Thanks for playing");
                       ^
    6 errors
    Compiles okay now.
    Java Code:
    import static java.lang.System.out;
    import static java.lang.System.in;
    import java.util.Scanner;
    import java.util.Random;
    
    class DTTTL {
    
        public static void main(String args[]) {
            Scanner myscanner = new Scanner(in);
            out.print("Enter a number between 1 and 10");
            int inputNumber = myscanner.nextInt();
    
            // Was missing the method operator "()" below:
            int randomNumber = new Random().nextInt(10)+ 1;
            if(randomNumber==inputNumber){
                out.println("*You win*");
            }
    
            out.println("That was a very good guess :-)");
            // Missing "." operator below.
    //        out println("The random number was ");
    //        out println(randomNumber + '.');
    //        out println("Thanks for playing");
    
        }
    }

  3. #3
    dwilliams is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Default Got it!

    Thanks very much. Bloody syntax. Bummer.
    Happy New Year to you

    David

  4. #4
    gcampton Guest

    Default

    JCreator gives same error messages, just make sure you have task view opened. (should be open by default)

    Attached Thumbnails Attached Thumbnails cannot find main - it is there though-jctest.jpg  
    Last edited by gcampton; 01-01-2010 at 09:51 AM.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    dwilliams is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Default Jcreator

    Hi,
    My free version of JCreator does not highlight syntax errors in any way. Do you know of a free one that does? I need to progress a bit more before I fork out.
    Thank you
    David

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Use NetBeans. It have bunch of much useful features. Incorrect syntax highlighting is pretty cool.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think Eclipse do the same. But I don't know exactly, I've never use it. Check it out if you want to use. By my experience I recommended NetBeans.

  9. #9
    dwilliams is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Default NetBeans

    Been using NetBeans all day, it's brilliant.
    Thanks very much
    David

  10. #10
    gcampton Guest

    Default

    Does that Netbeans have automatic error alternatives... pfftt

    use eclipse :P

  11. #11
    dwilliams is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Question Hmmm...

    Well Netbeans is much better than the free JCreator. Maybe I should try Eclipse as well.

    Thanks for the heads up.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gcampton View Post
    Does that Netbeans have automatic error alternatives... pfftt
    Of course. NetBeans shows you a list of alternative on the notification balloon on right hand side of the source editor window.

  13. #13
    gcampton Guest

    Default

    Quote Originally Posted by Eranga View Post
    Of course. NetBeans shows you a list of alternative on the notification balloon on right hand side of the source editor window.
    that's not autocompleted though

    Lol here come the flame wars...

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gcampton View Post
    that's not autocompleted though

    Lol here come the flame wars...
    It's not fully automated, but using a single click you can fix/replace text. :p

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Fight!
    Fight!
    Fight!
    :)

  16. #16
    gcampton Guest

    Default

    Quote Originally Posted by kcsatheesh View Post
    I use eclipse for 5 years!!
    much better than any other IDES
    Better than notepad? Ive been using it for 16 years.... so it must be the best

    :D

  17. #17
    gcampton Guest

    Default

    ok now I'm just getting silly.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gcampton View Post
    Better than notepad? Ive been using it for 16 years.... so it must be the best

    :D
    For 16 year? I wonder when you start to work on with Java.... If I'm correct Java release there first complete API, JDK 1.0 in 1996, January 23.... :p

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I agreed with you gcampton, that notepad is the best to dig into first step of Java. Working on with fundamentals on notepad helps a lot to improve skills in may ways. But working on with industrial level applications you must need an advance IDE, isn't it?

Similar Threads

  1. Could not find main class
    By Andyj in forum New To Java
    Replies: 2
    Last Post: 10-06-2009, 12:47 AM
  2. Cannot find Main class in Linux OS
    By msskiran in forum Eclipse
    Replies: 0
    Last Post: 04-10-2009, 02:04 AM
  3. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 04:07 PM
  4. JVM Could not find main class
    By banduskank in forum Advanced Java
    Replies: 2
    Last Post: 06-24-2008, 08:05 AM
  5. problems to find the main method
    By christina in forum Eclipse
    Replies: 2
    Last Post: 08-06-2007, 07:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •