473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A Run question.

nomad
664 Recognized Expert Contributor
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.FirstJavaProject.
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.
Mar 30 '07 #1
22 2135
JosAH
11,448 Recognized Expert MVP
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
Mar 31 '07 #2
nomad
664 Recognized Expert Contributor
Thanks Jos...
I did what you told me to do...
the error was listed as
java.lang.NoSuchMethodError: 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
Apr 2 '07 #3
JosAH
11,448 Recognized Expert MVP
Thanks Jos...
I did what you told me to do...
the error was listed as
java.lang.NoSuchMethodError: 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 (NoSuchMethodError: main)

You have to define that method.

kind regards,

Jos
Apr 2 '07 #4
nomad
664 Recognized Expert Contributor
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...

Expand|Select|Wrap|Line Numbers
  1.     public static void main(String[] args) {
  2.  
  3.         Employee_listing employeelist = new Employee_listing();
  4.         Scanner input_flag = new Scanner(System.in);
  5.  
  6.         int choice;
  7.         System.out.println("Make a Section: ");
  8.         System.out.println("1. Enter ");
  9.         System.out.println("2. Find ");
  10.         System.out.println("3. Exit ");
  11.         System.out.print("\nPlease press Enter afer each response");
  12.         System.out.println("Enter your chose please: ");
  13.         choice = input_flag.nextInt();
  14.         input_flag.nextLine();
  15.         if (choice == 1) {// if 1 is select go to makePerson
  16.             employeelist.inputEmployee();
  17.         }// close the if loop
  18.         if (choice == 2) {// if 2 is select go to find
  19.             employeelist.displayMatch();
  20.         }
  21.         if (choice == 3) {
  22.             System.out.printf("Good bye");
  23.         }// close if loop
  24.  
  25.     }// close public static void
Apr 2 '07 #5
JosAH
11,448 Recognized Expert MVP
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
Apr 2 '07 #6
nomad
664 Recognized Expert Contributor
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.NullPointerException
at company.Employee_listing.displayMatch(Employee_lis ting.java:223)
at company.Employee_listing.main(Employee_listing.jav a:272)

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

This is my Arraylist
Expand|Select|Wrap|Line Numbers
  1.     public void createEmployeeDatabase() {
  2.         Employees = new ArrayList<Employee>();
  3.  
  4.     }
thanks again
nomad
Apr 2 '07 #7
r035198x
13,262 MVP
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.NullPointerException
at company.Employee_listing.displayMatch(Employee_lis ting.java:223)
at company.Employee_listing.main(Employee_listing.jav a:272)

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

This is my Arraylist
Expand|Select|Wrap|Line Numbers
  1.     public void createEmployeeDatabase() {
  2.         Employees = new ArrayList<Employee>();
  3.  
  4.     }
thanks again
nomad
Can you post the code for the displayMatch method and indicate which line is line 223?
Apr 2 '07 #8
JosAH
11,448 Recognized Expert MVP
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.NullPointerException
at company.Employee_listing.displayMatch(Employee_lis ting.java:223)
at company.Employee_listing.main(Employee_listing.jav a: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
Apr 2 '07 #9
r035198x
13,262 MVP
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.
Apr 2 '07 #10
JosAH
11,448 Recognized Expert MVP
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
Apr 2 '07 #11
nomad
664 Recognized Expert Contributor
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


Expand|Select|Wrap|Line Numbers
  1. public void displayMatch() {
  2.         String id_flag = "";
  3.         Scanner input_flag = new Scanner(System.in);
  4.         System.out.println("Enter your chose please AB1234: ");
  5.         id_flag = input_flag.next();
  6.         boolean notfound = true;
  7.         for (Employee e : Employees) {
  8.             String emp = e.getEmpId();
  9.             if (emp.equals(id_flag)) {
  10.                 System.out.println("Hello" + ("e.lname"));
  11.                 notfound = false;
  12.             }
  13.         }
  14.         if (notfound == true) {
  15.             System.out.println("Error - Employee not found");
  16. // back to menu?
  17. }// 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
Apr 2 '07 #12
nomad
664 Recognized Expert Contributor
Question for you...
I have no data in the arraylist. Does this matter.

nomad
Apr 2 '07 #13
JosAH
11,448 Recognized Expert MVP
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
Apr 2 '07 #14
r035198x
13,262 MVP
line 223 is
for (Employee e : Employees) {

sure here is my code


Expand|Select|Wrap|Line Numbers
  1. public void displayMatch() {
  2.         String id_flag = "";
  3.         Scanner input_flag = new Scanner(System.in);
  4.         System.out.println("Enter your chose please AB1234: ");
  5.         id_flag = input_flag.next();
  6.         boolean notfound = true;
  7.         for (Employee e : Employees) {
  8.             String emp = e.getEmpId();
  9.             if (emp.equals(id_flag)) {
  10.                 System.out.println("Hello" + ("e.lname"));
  11.                 notfound = false;
  12.             }
  13.         }
  14.         if (notfound == true) {
  15.             System.out.println("Error - Employee not found");
  16. // back to menu?
  17. }// 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.
Apr 2 '07 #15
nomad
664 Recognized Expert Contributor
is it no data!!!!
Apr 2 '07 #16
nomad
664 Recognized Expert Contributor
I ran the debug a couple of times and I got this flag.

Class file editor

source not found
The source attachment does not contain the source for the file LRUCache.class.
You can change the source attachment by clicking Change Attached Source below:

OK when I click on the button. I have NO idea what I'm suppose to do.
do I select Workspace, or External file... or External Folder.

and I know its trying to find a Class ...

nomad
Apr 2 '07 #17
JosAH
11,448 Recognized Expert MVP
is it no data!!!!
An empty list doesn't cause a NullPointerException, it just causes your
for loop to do nothing. My guess for now is that the Employees variable is
simply null (just a guess though).

kind regards,

Jos
Apr 2 '07 #18
nomad
664 Recognized Expert Contributor
I just want to say thanks for the help so far.
A little more info might help you in helping me solve my problem.

When the client select either 1 or 2 and then they type in the id number, there is a boolean that will run a test to find that id.
If they are in the db then it will print out their info.
if they are not in the db then the client is prompt to enter the rest of their info.

Note I can get to the part where they type in the id. After that I get the error flag.

thanks
nomad
Apr 2 '07 #19
r035198x
13,262 MVP
I just want to say thanks for the help so far.
A little more info might help you in helping me solve my problem.

When the client select either 1 or 2 and then they type in the id number, there is a boolean that will run a test to find that id.
If they are in the db then it will print out their info.
if they are not in the db then the client is prompt to enter the rest of their info.

Note I can get to the part where they type in the id. After that I get the error flag.

thanks
nomad
Where have you initialised the Employees collection?
Apr 2 '07 #20
nomad
664 Recognized Expert Contributor
Where have you initialised the Employees collection?

I have not done that part. I need to read up and find out how to do that. Like I said my instructor is not very good. It's an Online class and he hardly helps at all.

thanks.
boy do I feel dumb
nomad
Apr 2 '07 #21
r035198x
13,262 MVP
I have not done that part. I need to read up and find out how to do that. Like I said my instructor is not very good. It's an Online class and he hardly helps at all.

thanks.
boy do I feel dumb
nomad
I wouldn't blame the instructor. Maybe you just need to spend a bit more time with the instructor. They are usually very good.

Well you need to initialize the collection first before you can do any operations with it.
Apr 2 '07 #22
nomad
664 Recognized Expert Contributor
I wouldn't blame the instructor. Maybe you just need to spend a bit more time with the instructor. They are usually very good.

Well you need to initialize the collection first before you can do any operations with it.
I don't mean to down grade him. I fact I never meet him. I have e-mail him with some problems and he responded back, but if I had another question about the project he never responds back.

I learn alot from this site and it's very confusing sometimes, esp with array and arraylist.
I have only taking one programing class and that was SQL a 5 years ago and have not used it hardly at all.

Thanks for the great help and hints.
nomad
Apr 2 '07 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4996
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
3
3058
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
53
4020
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
4695
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
4252
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.