Results 1 to 5 of 5
  1. #1
    Javanoobs is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default Error Exeption: java.lang.NoSuchMethodError: main

    when i compile my program, i get this error :
    java.lang.NoSuchMethodError: main
    Exception in thread "main" Java Result: 1

    my code is lik this

    import java.util.Scanner;
    public class Main {

    public static void main(String[] args) {
    int[] data = new int[8];
    int largest = data[0];



    System.out.println("Please enter 8 integers number");
    Scanner in = new Scanner(System.in);

    for(int i = 1; i <data.length;i++)
    {

    data[i]=in.nextInt();


    }
    for(int j=0; j< data.length ; j++)
    {
    if (data[j] > largest)
    {
    largest = data[j];
    }
    }
    System.out.println(largest);
    }

    }

    i don't actually knw the error so far, but it should be no problem because the main method format is no problem, but whenever i run it stil giv me the same error, can any give a good solution to solve this problem once and for all? or do i need to set the classpath or other things?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default

    Quote Originally Posted by Javanoobs View Post
    when i compile my program, i get this error :
    java.lang.NoSuchMethodError: main
    Exception in thread "main" Java Result: 1
    It runs fine for me. Are you sure this is the file you're running?

    Quote Originally Posted by Javanoobs View Post
    my code is lik this
    When posting code, make sure you use the code tags.

    Quote Originally Posted by Javanoobs View Post
    or do i need to set the classpath or other things?
    What happened when you tried that? Do you know that the classpath is? (hint: if your answer is "no", google is your friend)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    you must only be sure the javac is in your path, so when you type javac it's found. the other point is, change to the directory where the Main.java is and enter from there the command

    javac Main.java

    i tested it on my xp machine and i could compile your code without problems.

  4. #4
    Javanoobs is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    It runs fine for me. Are you sure this is the file you're running?



    When posting code, make sure you use the code tags.



    What happened when you tried that? Do you know that the classpath is? (hint: if your answer is "no", google is your friend)
    I have no problem running in my college lab but once i run in my home pc dekstop, i get the execption? perhaps some any other solutions you can suggest for me to handle on?
    P.S: sorry for the code tag because im new to this forum :) , and i know little about the classpath, but i know changing the classpath will affect some program to run abnormal...

  5. #5
    Javanoobs is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by j2me64 View Post
    you must only be sure the javac is in your path, so when you type javac it's found. the other point is, change to the directory where the Main.java is and enter from there the command

    javac Main.java

    i tested it on my xp machine and i could compile your code without problems.
    may i know how to check whether my javac is in my path? can giv direct solution to me?

Similar Threads

  1. error java.lang.NoSuchMethodError: main
    By Mars in forum New To Java
    Replies: 8
    Last Post: 10-05-2010, 05:37 PM
  2. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  3. [error] java.lang.NoSuchMethodError: main
    By jon80 in forum New To Java
    Replies: 1
    Last Post: 04-29-2009, 11:21 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 AM

Posting Permissions

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