473,469 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with static methods

122 New Member
I having trouble with my project and need a little help please


"The method inputEmployee cannot be declared static; static methods can only be declared in a static or top level type"
Part of my code where the problem is occurring.
Expand|Select|Wrap|Line Numbers
  1. public class Employee {
  2.     static ArrayList<Employee> arlist;
  3.     int empid = arlist.size();
  4.     /**
  5.      * displayMatch inputs a keyword from the user. It then iterates through the
  6.      * ArrayList of Employees and outputs each one to the screen if the Employee
  7.      * information contains the keyword.
  8.      */
  9.  
  10.     public static Employee inputEmployee() {
  11.         Employee temp = null;
  12.  
  13.         //prompt for data
  14.  
  15.         Scanner input_flag = new Scanner(System.in);
  16.         System.out.println("Enter Employee Id Number AB1234==>");
  17.         String empid = input_flag.next(); 

Here is the other half of the problem
"The method main cannot be declared static; static methods can only be declared in a static or top level type"
part of my code
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.  
  3.         arlist = new ArrayList<Employee>();
  4.  
  5.         kbd = new Scanner(System.in);
  6.         int choice;
  7.         System.out.println("Make a Section: "); 
Any help would be great...

thanks
sandy
Apr 10 '07 #1
1 3077
RedSon
5,000 Recognized Expert Expert
I having trouble with my project and need a little help please


"The method inputEmployee cannot be declared static; static methods can only be declared in a static or top level type"
Part of my code where the problem is occurring.
Expand|Select|Wrap|Line Numbers
  1. public class Employee {
  2.     static ArrayList<Employee> arlist;
  3.     int empid = arlist.size();
  4.     /**
  5.      * displayMatch inputs a keyword from the user. It then iterates through the
  6.      * ArrayList of Employees and outputs each one to the screen if the Employee
  7.      * information contains the keyword.
  8.      */
  9.  
  10.     public static Employee inputEmployee() {
  11.         Employee temp = null;
  12.  
  13.         //prompt for data
  14.  
  15.         Scanner input_flag = new Scanner(System.in);
  16.         System.out.println("Enter Employee Id Number AB1234==>");
  17.         String empid = input_flag.next(); 

Here is the other half of the problem
"The method main cannot be declared static; static methods can only be declared in a static or top level type"
part of my code
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.  
  3.         arlist = new ArrayList<Employee>();
  4.  
  5.         kbd = new Scanner(System.in);
  6.         int choice;
  7.         System.out.println("Make a Section: "); 
Any help would be great...

thanks
sandy
The first problem probably comes from using the same variable name twice, empid. The second problem probably comes from using arlist again but I cant be sure because I dont see how arlist is declared.
Apr 10 '07 #2

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

Similar topics

4
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned...
3
by: Sunny | last post by:
Hi again, in the past I have posted here a problem with static methods and abstract classes, and Jon Skeet and Richard Lowe have helped me to clarify the things. But now I have found another...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
13
by: Roy Gourgi | last post by:
Hi, How do I invoke the random number generator that was suggested by a few people. Ideally, what I would like to do is to instantiate the random no. generator with a seed value that does not...
6
by: ahart | last post by:
I'm pretty new to python and am trying to write a fairly small application to learn more about the language. I'm noticing some unexpected behavior in using lists in some classes to hold child...
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.