473,786 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception in thread "main" java.lang.NullP ointerException

122 New Member
Exception in thread "main" java.lang.NullP ointerException
at company.Employe e.inputEmployee (Employee.java: 172)
at company.Employe e.main(Employee .java:267)
which I got before...
Can someone please help me.
This is where the error occures line 172
for (Employee_listi ng e : employees) {
String emp = e.getEmpId();

line 267
if (choice == 1) { // if 1 is select go to makePerson
emp.inputEmploy ee();
Expand|Select|Wrap|Line Numbers
  1. Here are my 
  2.  
  3.  
  4. /**
  5.      * Constructors.
  6.      */
  7.  
  8.     public Employee_listing(String id, String fn, String ln, String st,
  9.             String ct, String zp, Double pr, Integer yw) {
  10.         empid = id;
  11.         fname = fn;
  12.         lname = ln;
  13.         street = st;
  14.         city = ct;
  15.         zip = zp;
  16.         yearsworked = yw;
  17.         payrate = pr;
  18.     }// close public EmployeeClass
  19.  
  20.     /*
  21.      * accessors make info available
  22.      */
  23.     public String getEmpId() {
  24.         return empid;
  25.     }
  26.  
  27.     public String getFname() {
  28.         return fname;
  29.     }
  30.  
  31.     public String getLname() {
  32.         return lname;
  33.     }
  34.  
  35.     public String getStreet() {
  36.         return street;
  37.     }
  38.  
  39.     public String getCity() {
  40.         return city;
  41.     }
  42.  
  43.     public String getZip() {
  44.         return zip;
  45.     }
  46.  
  47.     public Integer getYearsworked() {
  48.         return yearsworked;
  49.     }
  50.  
  51.     public Double getPayrate() {
  52.         return payrate;
  53.     }
  54.  
  55.  
  56. public void inputEmployee() {
  57.  
  58.             Employee_listing MyEmployee;
  59.  
  60.             // prompt for data
  61.  
  62.             Scanner input_flag = new Scanner(System.in);
  63.             System.out.println("Enter Employee Id Number AB1234==>");
  64.             String empid = input_flag.next();
  65.             String id_flag = "";
  66.             boolean notfound = true;
  67.             for (Employee_listing e : employees) {
  68.                 String emp = e.getEmpId();
  69.                 if (emp.equals(id_flag)) {
  70.                     System.out.println("Hello" + ("e.lname"));
  71.                     notfound = false;
  72.                 }
  73.             }
  74.             if (notfound == true) {
  75. .....
  76. }
  77.         public static void main(String[] args) {
  78.             Employee emp = new Employee();
  79.             Scanner kbd = new Scanner(System.in);
  80.             int choice;
  81.             System.out.println("Make a Section: ");
  82.             System.out.println("1. Enter ");
  83.             System.out.println("2. Find ");
  84.             System.out.println("3. Exit ");
  85.             System.out.print("\nPlease press Enter afer each response");
  86.             System.out.println("Enter your chose please: ");
  87.             choice = kbd.nextInt();
  88.             kbd.nextLine();
  89.             if (choice == 1) { // if 1 is select go to makePerson
  90.                 emp.inputEmployee();
  91. ....
  92. }
  93.  
thanks
sandyw
Apr 19 '07
12 6685
sandyw
122 New Member
OK...
I still can not figure out this Exception in thread "main" java.lang.NullP ointerException

so if someone has the time to help me
or tell me how to fix it by example that would be great.
here is my complete code.

Expand|Select|Wrap|Line Numbers
  1. package company;
  2.  
  3. import java.util.*;
  4.  
  5. /**
  6.  *
  7.  * @author  ** 
  8.  
  9.  */
  10.  
  11. /**
  12.  * This program will maintain Employee Data for a company. The user will be able
  13.  * to enter new employee data and search on existing employee data. This program
  14.  * will use Arrays or an ArrayList to maintain the information. You will create
  15.  * an Employee Class and from this class create Employee Objects. These objects
  16.  * will be stored in an Array or ArrayList in such a way that they can be
  17.  * searched by the user.
  18.  */
  19.  
  20. class Employee_listing {
  21.  
  22.     private String empid;
  23.  
  24.     private String lname;
  25.  
  26.     private String fname;
  27.  
  28.     private String street;
  29.  
  30.     private String city;
  31.  
  32.     private String zip;
  33.  
  34.     private Integer yearsworked;
  35.  
  36.     private Double payrate;
  37.  
  38.     public Employee_listing(String id) {
  39.         empid = id;
  40.     }// close the employeeclass loop
  41.  
  42.     /**
  43.      * Constructors.
  44.      */
  45.  
  46.     public Employee_listing(String id, String fn, String ln, String st,
  47.             String ct, String zp, Double pr, Integer yw) {
  48.         empid = id;
  49.         fname = fn;
  50.         lname = ln;
  51.         street = st;
  52.         city = ct;
  53.         zip = zp;
  54.         yearsworked = yw;
  55.         payrate = pr;
  56.     }// close public EmployeeClass
  57.  
  58.     /*
  59.      * accessors make info available
  60.      */
  61.     public String getEmpId() {
  62.         return empid;
  63.     }
  64.  
  65.     public String getFname() {
  66.         return fname;
  67.     }
  68.  
  69.     public String getLname() {
  70.         return lname;
  71.     }
  72.  
  73.     public String getStreet() {
  74.         return street;
  75.     }
  76.  
  77.     public String getCity() {
  78.         return city;
  79.     }
  80.  
  81.     public String getZip() {
  82.         return zip;
  83.     }
  84.  
  85.     public Integer getYearsworked() {
  86.         return yearsworked;
  87.     }
  88.  
  89.     public Double getPayrate() {
  90.         return payrate;
  91.     }
  92.  
  93.     /*
  94.      * Mutator Methods
  95.      */
  96.     public void setEmpId(String id) {
  97.         empid = id;
  98.     }
  99.  
  100.     public void setFname(String fn) {
  101.         fname = fn;
  102.     }
  103.  
  104.     public void setLname(String ln) {
  105.         lname = ln;
  106.     }
  107.  
  108.     public void setStreet(String st) {
  109.         street = st;
  110.     }
  111.  
  112.     public void setCity(String ct) {
  113.         city = ct;
  114.     }
  115.  
  116.     public void setZip(String zp) {
  117.         zip = zp;
  118.     }
  119.  
  120.     public void setYW(Integer yw) {
  121.         yearsworked = yw;
  122.     }
  123.  
  124.     public void setPR(Double pr) {
  125.         payrate = pr;
  126.     }
  127. }
  128.     /**
  129.      * The EmployeeDatabase class stores each Employee in an arraylist. Methods
  130.      * exist to add new Employees, search Employees, and print Employees to the
  131.      * console.
  132.      */
  133.     public class Employee {
  134.  
  135.         public ArrayList<Employee_listing> employees;// ArrayList of
  136.  
  137.         // contact
  138.  
  139.  
  140.  
  141.         public void createEmployeeDB() {
  142.             employees = new ArrayList<Employee_listing>();
  143.             Employee_listing temp = new Employee_listing("DW12341");
  144.             temp.setFname("Sandy");
  145.             temp.setLname("Wong");
  146.             temp.setStreet("12345 My St");
  147.             temp.setCity("Fullerton");
  148.             temp.setZip("90631");
  149.             temp.setYW(2);
  150.             temp.setPR(5000.00);
  151.             employees.add(temp);
  152.         }
  153.  
  154.         /**
  155.          * displayMatch inputs a keyword from the user. It then iterates through
  156.          * the ArrayList of Employees and outputs each one to the screen if the
  157.          * Employee information contains the keyword.
  158.          */
  159.  
  160.         public void inputEmployee() {
  161.  
  162.             Employee_listing MyEmployee;
  163.  
  164.             // prompt for data
  165.  
  166.             Scanner input_flag = new Scanner(System.in);
  167.             System.out.println("Enter Employee Id Number AB1234==>");
  168.             String empid = input_flag.next();
  169.  
  170.             boolean notfound = true;
  171.             for (Employee_listing e : employees) {
  172.                 System.out.println(" a"+e.getLname());
  173.                 String emp = e.getEmpId();
  174.  
  175.                 if (emp.equals(empid)) {
  176.                     System.out.println("Hello" + ("e.lname"));
  177.                     notfound = false;
  178.                 }
  179.             }
  180.             if (notfound == true) {
  181.  
  182.             System.out.print("Enter Last Name Doe==>");
  183.             String ln = input_flag.next();
  184.  
  185.             System.out.print("Enter First Name John==>");
  186.             String fn = input_flag.next();
  187.  
  188.             System.out.print("Enter Street ==>");
  189.             String st = input_flag.next();
  190.  
  191.             System.out.print("Enter City ==>");
  192.             String ct = input_flag.next();
  193.  
  194.             System.out.print("Enter Zip ==>");
  195.             String zp = input_flag.next();
  196.  
  197.             System.out.print("Enter years worked ==>");
  198.             Integer yw = input_flag.nextInt();
  199.  
  200.             System.out.print("Enter payrate as double ==>");
  201.             Double pr = input_flag.nextDouble();
  202.  
  203.             // make an object
  204.             MyEmployee = new Employee_listing(empid, ln, fn, st, ct, zp, pr, yw);
  205.             employees.add(MyEmployee);
  206.  
  207.             System.out.println("The are this many Employee in the System:");
  208.             System.out.println(employees.size());
  209.             }
  210.             // still need to add a counter
  211.  
  212.         }// close the displayMatch
  213.  
  214.         /**
  215.          * displayMatch inputs a keyword from the user. It then iterates through
  216.          * the ArrayList of Employees and outputs each one to the screen if the
  217.          * Employee information contains the keyword.
  218.          * @return
  219.          */
  220.         public void displayMatch() {
  221.  
  222.             Scanner input_flag = new Scanner(System.in);
  223.             System.out.println("Enter Employee Id Number AB1234==>");
  224.             String empid = input_flag.next();
  225.             boolean notfound = true;
  226.             for (Employee_listing e : employees) {
  227.                 String emp = e.getEmpId();
  228.                 if (emp.equals(empid)) {
  229.                     System.out.println("You need to go back to Main Menu");
  230.                     notfound = false;
  231.                 }
  232.             }
  233.             if (notfound == true) {
  234.  
  235.             for (Employee_listing e : employees) {
  236.                 System.out.printf("Employee Id: %s \n", e.getEmpId());
  237.                 System.out.printf("Name is %s - %s \n", e.getFname(), e
  238.                         .getLname());
  239.                 System.out.printf("Address is %s  \n", e.getStreet());
  240.                 System.out.printf("City is %s \n", e.getCity());
  241.                 System.out.printf("Zip is %s  \n", e.getZip());
  242.                 System.out.printf("Pay is %s  \n", e.getPayrate());
  243.                 System.out.printf("Years worked are %d\n", e.getYearsworked());
  244.                 System.out.println("--------------------");
  245.             }
  246.             }
  247.         }// close the displayMatch
  248.  
  249.         /**
  250.          * @param Add
  251.          *            a employee to the db. using a scanner to see if an
  252.          *            Employee is in the db if no add them
  253.          */
  254.  
  255.         public static void main(String[] args) {
  256.             Employee emp = new Employee();
  257.             Scanner kbd = new Scanner(System.in);
  258.             int choice;
  259.             System.out.println("Make a Section: ");
  260.             System.out.println("1. Enter ");
  261.             System.out.println("2. Find ");
  262.             System.out.println("3. Exit ");
  263.             System.out.print("\nPlease press Enter afer each response");
  264.             System.out.println("Enter your chose please: ");
  265.             choice = kbd.nextInt();
  266.             kbd.nextLine();
  267.             if (choice == 1) { // if 1 is select go to makePerson
  268.                 emp.inputEmployee();
  269.  
  270.             } // close the if loop
  271.  
  272.             if (choice == 2) { // if 2 is select go to find
  273.                 emp.displayMatch();
  274.  
  275.             }// close the choice==2
  276.             if (choice == 3) {
  277.                 System.out.printf("Good bye");
  278.             }// close the choice == 3
  279.  
  280.         }// close public static void
  281.  
  282.     }// close public class Employee
Sandyw
so near yet so far away.
Apr 20 '07 #11
sandyw
122 New Member
I still need help see above
Apr 25 '07 #12
r035198x
13,262 MVP
I still need help see above
Look at your program flow again from the main method. When do you initialize the employees list? You should find that you are trying to access the list before it is initialized.
Apr 26 '07 #13

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

Similar topics

0
3012
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's webpage and installed it using SGI's swmgr application. The installation was very straight forward and there were no errors when I installed the package. Then I ran /usr/java2/bin/javac SelectSockets.java to make the SelectSockets.class file.
1
9124
by: Andy Howells | last post by:
Can anybody help me on this? I am getting the below error but have not got a clue why. The file in my classpath eing used has the class that it says is not defined. Any ideas? I am running java version 1.4.0 and WMQ Series version 5.3 with CSD04. Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/server/MQSESSION at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:67) at...
9
3129
by: jith87 | last post by:
What is ths error.????? I m nw loading the JDBC driver for connection with MySql. Exception in thread "main" java.lang.NoClassDefFoundError: MySQLJDBCDriverTest
1
1790
by: GHKASHYAP | last post by:
Hi this is the exception i am getting when i am trying to run this application: Exception in thread "main" java.lang.NullPointerException thanks in advance.. package com.inventive.StockMarketTrading; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent;
3
6445
by: Ananthu | last post by:
Hi This is my codings in order to access mysql database from java. Codings: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;
9
3286
by: tiyaramunna | last post by:
I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting the following error Exception in thread "main" java.lang.NoClassDefFoundError: test Caused by: java.lang.ClassNotFoundException: test at java.net.URLClassLoader$1.run(Unknown Source) at...
4
14733
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp However, the statement below produces the error: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar" -jar CurrentStrobe.jar Exception in thread "main"...
1
13742
by: jimgym1989 | last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException this is my code /** * @(#)textFileRead.java * * * @author * @version 1.00 2008/10/17 */
3
7661
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at sortmergejoin.MergeJoin.Field(MergeJoin.java:204) at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84) at sortmergejoin.MergeJoin.<init>(MergeJoin.java:34) at sortmergejoin.Main.main(Main.java:24) Java Result: 1"
1
6758
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1041) at java.awt.Container.add(Container.java:365) at orderingsystem.OrderingSystem.<init>(OrderingSystem.java:261) at...
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
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 we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.