Results 1 to 8 of 8
  1. #1
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Default Error during running

    Hi,
    I am an engineering student IT department.
    I have error during running an simple java program.
    I have set the path correctly and its compiling correctly but when i give
    java filename it shows an error saying exception in main thread.

    The code i used is
    Java Code:
    class ak
    {
    public static void main(String arg[])
    {
    System.out.println("hai");
    }
    }
    For me appletviewer is working correctly problem only with when i run java program.

    Please help me solve my problem
    Last edited by ak88; 07-26-2009 at 04:53 AM.

  2. #2
    hero is offline Member
    Join Date
    Jul 2009
    Posts
    20
    Rep Power
    0

    Default

    What do you mean by "problem only with when i run java program"?
    Dit you exported it into a jar file?

    Can you post the error please?
    And if you post a code please use CODE-tags.
    [CODE]Your code goes here.[/CODE]

  3. #3
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Default

    when i compile that piece of code no error but when i run the program i get an error
    saying Exception in no main foundI didnt use any jar and all

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Copy, paste and post the command you are using and the exact and entire error message you receive.

    To compile and run that code from the directory containing ak.java you would typically use something like:

    Java Code:
    > javac -cp . ak.java
    > java -cp . ak
    Note that "ak" is not a very good name for a Java class. These start with a capital letter (hance, Ak). Part of the reason for this is that consistent case naming conventions help reduce errors like specifying the class name incorrectly on the command line.

  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

    Default

    How did you compile and run your code, as pbrockway2 says please provide more details here. So it's easy to help you.

  6. #6
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Default

    compiled using javac ak.java
    while running
    C:\>java ak
    Exception in thread "main" java.lang.NoSuchMethodError: main

  7. #7
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    definitely not a coding problem, but you most likely have something wrong with your classpaths or whatnot. are you aware of packages? trying putting your class into a package and running it that way. it should work with the default (no defined) package, but it's generally frowned upon to do so.

  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

    Yes, so the next thing to know is all about the classpath setup. But if the classpath is not setup correctly, that javac command complain about that "javac is not recognized command......"

Similar Threads

  1. Error running java program using URL
    By gio123bg in forum New To Java
    Replies: 6
    Last Post: 06-30-2009, 06:26 PM
  2. error running java program
    By bdasilva in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 01:46 AM
  3. [SOLVED] Error while running eclipse
    By kimskams80 in forum Eclipse
    Replies: 3
    Last Post: 07-02-2008, 11:31 AM
  4. error while running jar file
    By ernieBob in forum NetBeans
    Replies: 1
    Last Post: 03-25-2008, 11:13 AM
  5. Replies: 7
    Last Post: 08-12-2007, 03:47 PM

Posting Permissions

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