473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems with static methods

122 100+
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 3073
RedSon
5,000 Expert 4TB
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.