A Run question.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    A Run question.

    I have a question in which I want to run my java program.
    I'm using Eclipse as my application.
    When I want to run my program I do a right-click on the mouse and choose
    Run as (arrow down to) run...
    A Window called Run shows on the screen.
    In the Main class: I have a chose to make by pushing the Search...button
    In doing so I have a list of options to chose from.
    Matching types which has my project (Employee) or there is another on
    under ----Workspace matches------ which again it is listed (Sometimes it listed)

    Question is which one do I use. I get an Erros in Project Window.
    Erros exist in required Project.FirstJa vaProject.
    Contune launch?
    I can not figure out where the errors are at considering I'm usign Eclipse.



    thanks
    damon
    PS no matter which one I use I get an error.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    When you navigate to Window > Show View > Problems you can see details
    of all problems in all open projects. Click on one of the problems and Eclipse
    will open the corresponding source for you. Note that the left border of every
    source show you the lines which contain errors. If you move your mouse over
    those little icons you get a nice description of the error again.

    kind regards,

    Jos

    Comment

    • nomad
      Recognized Expert Contributor
      • Mar 2007
      • 664

      #3
      Thanks Jos...
      I did what you told me to do...
      the error was listed as
      java.lang.NoSuc hMethodError: main
      Exception in thread "main"

      How do I go about find out how to fix this error.
      Do you need me to post my code....

      thanks
      nomad

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by nomad
        Thanks Jos...
        I did what you told me to do...
        the error was listed as
        java.lang.NoSuc hMethodError: main
        Exception in thread "main"

        How do I go about find out how to fix this error.
        Do you need me to post my code....

        thanks
        nomad
        The JVM (Java Virtual machine) always starts one of your classes by calling
        the public static void main(String[] args) method in that class. In your case
        that particular class doesn't contain such a method (NoSuchMethodEr ror: main)

        You have to define that method.

        kind regards,

        Jos

        Comment

        • nomad
          Recognized Expert Contributor
          • Mar 2007
          • 664

          #5
          that's what I thought it meant.
          but I have this at the end of my project...

          Thanks
          nomad
          ps is this right....
          The rest of the projecgt is done with one class, one public class and severl public void...

          Code:
          	public static void main(String[] args) {
          
          		Employee_listing employeelist = new Employee_listing();
          		Scanner input_flag = new Scanner(System.in);
          
          		int choice;
          		System.out.println("Make a Section: ");
          		System.out.println("1. Enter ");
          		System.out.println("2. Find ");
          		System.out.println("3. Exit ");
          		System.out.print("\nPlease press Enter afer each response");
          		System.out.println("Enter your chose please: ");
          		choice = input_flag.nextInt();
          		input_flag.nextLine();
          		if (choice == 1) {// if 1 is select go to makePerson
          			employeelist.inputEmployee();
          		}// close the if loop
          		if (choice == 2) {// if 2 is select go to find
          			employeelist.displayMatch();
          		}
          		if (choice == 3) {
          			System.out.printf("Good bye");
          		}// close if loop
          
          	}// close public static void

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Eclipse uses "launch configurations" to start your Java programs. Navigage
            to Run > Run ... and select "Java Application" next press the "new launch"
            button at the top left. Then that big dialog comes up; name your new config,
            specify the project, the name of the class that contains the main method;
            click "apply" and then run your program.

            Note that you can have different launch configurations and you can define
            new ones for every open project in your workspace.

            kind regards,

            Jos

            Comment

            • nomad
              Recognized Expert Contributor
              • Mar 2007
              • 664

              #7
              Thanks Jos...
              I figure it out with your info.
              I'm very new to Java and my instructor is not very helpful that goodness for sites like this one.
              Your suggestion did not work, until I created a new Prpject. I then moved my Package to the new Project.
              But now I get a new error:
              Exception in thread "main" java.lang.NullP ointerException
              at company.Employe e_listing.displ ayMatch(Employe e_listing.java: 223)
              at company.Employe e_listing.main( Employee_listin g.java:272)

              Note I have a Array and Arraylist.
              Any ideal how I can solve this problem

              This is my Arraylist
              Code:
              	public void createEmployeeDatabase() {
              		Employees = new ArrayList<Employee>();
              
              	}
              thanks again
              nomad

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by nomad
                Thanks Jos...
                I figure it out with your info.
                I'm very new to Java and my instructor is not very helpful that goodness for sites like this one.
                Your suggestion did not work, until I created a new Prpject. I then moved my Package to the new Project.
                But now I get a new error:
                Exception in thread "main" java.lang.NullP ointerException
                at company.Employe e_listing.displ ayMatch(Employe e_listing.java: 223)
                at company.Employe e_listing.main( Employee_listin g.java:272)

                Note I have a Array and Arraylist.
                Any ideal how I can solve this problem

                This is my Arraylist
                Code:
                	public void createEmployeeDatabase() {
                		Employees = new ArrayList<Employee>();
                 
                	}
                thanks again
                nomad
                Can you post the code for the displayMatch method and indicate which line is line 223?

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by nomad
                  Thanks Jos...
                  I figure it out with your info.
                  I'm very new to Java and my instructor is not very helpful that goodness for sites like this one.
                  Your suggestion did not work, until I created a new Prpject. I then moved my Package to the new Project.
                  Good; may I suggest that you remove the old project including all its resources?
                  It avoids cluttering you harddisk and cluttering Eclipe's workspace.

                  But now I get a new error:
                  Exception in thread "main" java.lang.NullP ointerException
                  at company.Employe e_listing.displ ayMatch(Employe e_listing.java: 223)
                  at company.Employe e_listing.main( Employee_listin g.java:272)

                  Note I have a Array and Arraylist.
                  Any ideal how I can solve this problem
                  That is also good: it shows that Eclipse can run your project. All you have to
                  do now is solve your bug ;-)

                  Navigate to Run > Debug; select your project and select the button "stop in main".
                  Next Eclipse will switch to its "debugging perspective" where you van step
                  every single statement of your code; hint: F7 steps over an entire method
                  while F5 steps "into" the method. Give it a try and experiment with it all a bit.

                  Pay special attention to the little panel at the top right corner; it displays the
                  values of all variables in scope.

                  kind regards,

                  Jos

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by JosAH
                    Good; may I suggest that you remove the old project including all its resources?
                    It avoids cluttering you harddisk and cluttering Eclipe's workspace.



                    That is also good: it shows that Eclipse can run your project. All you have to
                    do now is solve your bug ;-)

                    Navigate to Run > Debug; select your project and select the button "stop in main".
                    Next Eclipse will switch to its "debugging perspective" where you van step
                    every single statement of your code; hint: F7 steps over an entire method
                    while F5 steps "into" the method. Give it a try and experiment with it all a bit.

                    Pay special attention to the little panel at the top right corner; it displays the
                    values of all variables in scope.

                    kind regards,

                    Jos
                    Now that you've said it I think that is actually much better than having him post the code.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by r035198x
                      Now that you've said it I think that is actually much better than having him post the code.
                      I saw those big line numbers and just went *eeew!* Nobody wants to plough
                      through that much of code; Eclipse itself doesn't care though ;-)

                      kind regards,

                      Jos

                      Comment

                      • nomad
                        Recognized Expert Contributor
                        • Mar 2007
                        • 664

                        #12
                        Originally posted by r035198x
                        Can you post the code for the displayMatch method and indicate which line is line 223?
                        line 223 is
                        for (Employee e : Employees) {

                        sure here is my code


                        Code:
                        public void displayMatch() {
                        		String id_flag = "";
                        		Scanner input_flag = new Scanner(System.in);
                        		System.out.println("Enter your chose please AB1234: ");
                        		id_flag = input_flag.next();
                        		boolean notfound = true;
                        		for (Employee e : Employees) {
                        			String emp = e.getEmpId();
                        			if (emp.equals(id_flag)) {
                        				System.out.println("Hello" + ("e.lname"));
                        				notfound = false;
                        			}
                        		}
                        		if (notfound == true) {
                        			System.out.println("Error - Employee not found");
                        // back to menu?
                        }// need to find out if this needs to go below printing
                        I would like help and at the same time I'm going to look into Jos suggestion.

                        thanks
                        nomad

                        Comment

                        • nomad
                          Recognized Expert Contributor
                          • Mar 2007
                          • 664

                          #13
                          Question for you...
                          I have no data in the arraylist. Does this matter.

                          nomad

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #14
                            Originally posted by nomad
                            I would like help and at the same time I'm going to look into Jos suggestion.

                            thanks
                            nomad
                            Degugging is an art form; first press the F6 key continuously; somewhere in
                            your code that null pointer exception is thrown. Restart your debug session
                            again (see my previous reply) but instead of stepping *over* that last method
                            that threw the Exception, step *into* it (using the F5 key). Rinse and repeat
                            until you've nailed the statement that caused the error.

                            kind regards,

                            Jos

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by nomad
                              line 223 is
                              for (Employee e : Employees) {

                              sure here is my code


                              Code:
                              public void displayMatch() {
                              		String id_flag = "";
                              		Scanner input_flag = new Scanner(System.in);
                              		System.out.println("Enter your chose please AB1234: ");
                              		id_flag = input_flag.next();
                              		boolean notfound = true;
                              		for (Employee e : Employees) {
                              			String emp = e.getEmpId();
                              			if (emp.equals(id_flag)) {
                              				System.out.println("Hello" + ("e.lname"));
                              				notfound = false;
                              			}
                              		}
                              		if (notfound == true) {
                              			System.out.println("Error - Employee not found");
                              // back to menu?
                              }// need to find out if this needs to go below printing
                              I would like help and at the same time I'm going to look into Jos suggestion.

                              thanks
                              nomad
                              But you should know by now where the problem is.

                              Comment

                              Working...