Results 1 to 3 of 3
  1. #1
    john_java is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Can't compile with Eclipse

    I've been doing some Java projects at school using Eclipse and i've got some homework to do during spring break.
    I've downloaded Eclipse and all the needed Java plugins.
    Now when I open a Java project that I worked on at school, it shows me the code, but when I click on "run as" it gives two options, both are "ants" or whatever. Doesn't matter which one i choose it won't show me the output, the actual program... Why ?
    Any help ?

    For example, this code worked perfectly fine at school, but won't do anything at home:

    import java.util.Scanner;

    class Car

    {
    Scanner scan = new Scanner(System.in);
    double milesStart;
    double milesEnd;
    double gallons;

    Car(double start, double end, double gals)
    {
    System.out.println("Enter starting miles: ");
    start = scan.nextDouble();
    milesStart = start;
    System.out.println("Enter ending miles: ");
    end = scan.nextDouble();
    milesEnd = end;

    System.out.println("Enter gallons used: ");
    gals = scan.nextDouble();
    gallons = gals;
    }
    double calculateMPG()
    {
    return (milesEnd - milesStart)/gallons;
    }

    boolean gasHog()
    {

    }

    boolean economyCar()
    {

    }
    }



    class MPGTester
    {
    public static void main (String[] args)
    {
    Car car = new Car(0.0, 0.0, 0.0);
    System.out.println( "MPG: " + car.calculateMPG() );
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Can't compile with Eclipse

    Post moved to the IDE's thread.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Can't compile with Eclipse

    Right click on the java file containing the main() method, then choose RunAs...
    This tells Eclipse what class you want to run (a project may contain many classes with a main(), or many different ways of running as well).
    This is then added to your list of Run Configurations, which are accessible from the Run buttons (the green ones in the tool bar) should you not wish to always hunt around for the correct class to run.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 2
    Last Post: 10-11-2013, 09:26 AM
  2. Replies: 1
    Last Post: 04-27-2011, 10:08 AM
  3. Trying to compile an eclipse RCP program
    By mattlindsay in forum Eclipse
    Replies: 0
    Last Post: 04-14-2011, 10:40 PM
  4. Replies: 0
    Last Post: 03-27-2011, 05:49 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
  •