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(); -
Here are my
-
-
-
/**
-
* Constructors.
-
*/
-
-
public Employee_listing(String id, String fn, String ln, String st,
-
String ct, String zp, Double pr, Integer yw) {
-
empid = id;
-
fname = fn;
-
lname = ln;
-
street = st;
-
city = ct;
-
zip = zp;
-
yearsworked = yw;
-
payrate = pr;
-
}// close public EmployeeClass
-
-
/*
-
* accessors make info available
-
*/
-
public String getEmpId() {
-
return empid;
-
}
-
-
public String getFname() {
-
return fname;
-
}
-
-
public String getLname() {
-
return lname;
-
}
-
-
public String getStreet() {
-
return street;
-
}
-
-
public String getCity() {
-
return city;
-
}
-
-
public String getZip() {
-
return zip;
-
}
-
-
public Integer getYearsworked() {
-
return yearsworked;
-
}
-
-
public Double getPayrate() {
-
return payrate;
-
}
-
-
-
public void inputEmployee() {
-
-
Employee_listing MyEmployee;
-
-
// prompt for data
-
-
Scanner input_flag = new Scanner(System.in);
-
System.out.println("Enter Employee Id Number AB1234==>");
-
String empid = input_flag.next();
-
String id_flag = "";
-
boolean notfound = true;
-
for (Employee_listing e : employees) {
-
String emp = e.getEmpId();
-
if (emp.equals(id_flag)) {
-
System.out.println("Hello" + ("e.lname"));
-
notfound = false;
-
}
-
}
-
if (notfound == true) {
-
.....
-
}
-
public static void main(String[] args) {
-
Employee emp = new Employee();
-
Scanner kbd = 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 = kbd.nextInt();
-
kbd.nextLine();
-
if (choice == 1) { // if 1 is select go to makePerson
-
emp.inputEmployee();
-
....
-
}
-
thanks
sandyw
Apr 19 '07
12 6685
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. - package company;
-
-
import java.util.*;
-
-
/**
-
*
-
* @author **
-
-
*/
-
-
/**
-
* This program will maintain Employee Data for a company. The user will be able
-
* to enter new employee data and search on existing employee data. This program
-
* will use Arrays or an ArrayList to maintain the information. You will create
-
* an Employee Class and from this class create Employee Objects. These objects
-
* will be stored in an Array or ArrayList in such a way that they can be
-
* searched by the user.
-
*/
-
-
class Employee_listing {
-
-
private String empid;
-
-
private String lname;
-
-
private String fname;
-
-
private String street;
-
-
private String city;
-
-
private String zip;
-
-
private Integer yearsworked;
-
-
private Double payrate;
-
-
public Employee_listing(String id) {
-
empid = id;
-
}// close the employeeclass loop
-
-
/**
-
* Constructors.
-
*/
-
-
public Employee_listing(String id, String fn, String ln, String st,
-
String ct, String zp, Double pr, Integer yw) {
-
empid = id;
-
fname = fn;
-
lname = ln;
-
street = st;
-
city = ct;
-
zip = zp;
-
yearsworked = yw;
-
payrate = pr;
-
}// close public EmployeeClass
-
-
/*
-
* accessors make info available
-
*/
-
public String getEmpId() {
-
return empid;
-
}
-
-
public String getFname() {
-
return fname;
-
}
-
-
public String getLname() {
-
return lname;
-
}
-
-
public String getStreet() {
-
return street;
-
}
-
-
public String getCity() {
-
return city;
-
}
-
-
public String getZip() {
-
return zip;
-
}
-
-
public Integer getYearsworked() {
-
return yearsworked;
-
}
-
-
public Double getPayrate() {
-
return payrate;
-
}
-
-
/*
-
* Mutator Methods
-
*/
-
public void setEmpId(String id) {
-
empid = id;
-
}
-
-
public void setFname(String fn) {
-
fname = fn;
-
}
-
-
public void setLname(String ln) {
-
lname = ln;
-
}
-
-
public void setStreet(String st) {
-
street = st;
-
}
-
-
public void setCity(String ct) {
-
city = ct;
-
}
-
-
public void setZip(String zp) {
-
zip = zp;
-
}
-
-
public void setYW(Integer yw) {
-
yearsworked = yw;
-
}
-
-
public void setPR(Double pr) {
-
payrate = pr;
-
}
-
}
-
/**
-
* The EmployeeDatabase class stores each Employee in an arraylist. Methods
-
* exist to add new Employees, search Employees, and print Employees to the
-
* console.
-
*/
-
public class Employee {
-
-
public ArrayList<Employee_listing> employees;// ArrayList of
-
-
// contact
-
-
-
-
public void createEmployeeDB() {
-
employees = new ArrayList<Employee_listing>();
-
Employee_listing temp = new Employee_listing("DW12341");
-
temp.setFname("Sandy");
-
temp.setLname("Wong");
-
temp.setStreet("12345 My St");
-
temp.setCity("Fullerton");
-
temp.setZip("90631");
-
temp.setYW(2);
-
temp.setPR(5000.00);
-
employees.add(temp);
-
}
-
-
/**
-
* displayMatch inputs a keyword from the user. It then iterates through
-
* the ArrayList of Employees and outputs each one to the screen if the
-
* Employee information contains the keyword.
-
*/
-
-
public void inputEmployee() {
-
-
Employee_listing MyEmployee;
-
-
// prompt for data
-
-
Scanner input_flag = new Scanner(System.in);
-
System.out.println("Enter Employee Id Number AB1234==>");
-
String empid = input_flag.next();
-
-
boolean notfound = true;
-
for (Employee_listing e : employees) {
-
System.out.println(" a"+e.getLname());
-
String emp = e.getEmpId();
-
-
if (emp.equals(empid)) {
-
System.out.println("Hello" + ("e.lname"));
-
notfound = false;
-
}
-
}
-
if (notfound == true) {
-
-
System.out.print("Enter Last Name Doe==>");
-
String ln = input_flag.next();
-
-
System.out.print("Enter First Name John==>");
-
String fn = input_flag.next();
-
-
System.out.print("Enter Street ==>");
-
String st = input_flag.next();
-
-
System.out.print("Enter City ==>");
-
String ct = input_flag.next();
-
-
System.out.print("Enter Zip ==>");
-
String zp = input_flag.next();
-
-
System.out.print("Enter years worked ==>");
-
Integer yw = input_flag.nextInt();
-
-
System.out.print("Enter payrate as double ==>");
-
Double pr = input_flag.nextDouble();
-
-
// make an object
-
MyEmployee = new Employee_listing(empid, ln, fn, st, ct, zp, pr, yw);
-
employees.add(MyEmployee);
-
-
System.out.println("The are this many Employee in the System:");
-
System.out.println(employees.size());
-
}
-
// still need to add a counter
-
-
}// close the displayMatch
-
-
/**
-
* displayMatch inputs a keyword from the user. It then iterates through
-
* the ArrayList of Employees and outputs each one to the screen if the
-
* Employee information contains the keyword.
-
* @return
-
*/
-
public void displayMatch() {
-
-
Scanner input_flag = new Scanner(System.in);
-
System.out.println("Enter Employee Id Number AB1234==>");
-
String empid = input_flag.next();
-
boolean notfound = true;
-
for (Employee_listing e : employees) {
-
String emp = e.getEmpId();
-
if (emp.equals(empid)) {
-
System.out.println("You need to go back to Main Menu");
-
notfound = false;
-
}
-
}
-
if (notfound == true) {
-
-
for (Employee_listing e : employees) {
-
System.out.printf("Employee Id: %s \n", e.getEmpId());
-
System.out.printf("Name is %s - %s \n", e.getFname(), e
-
.getLname());
-
System.out.printf("Address is %s \n", e.getStreet());
-
System.out.printf("City is %s \n", e.getCity());
-
System.out.printf("Zip is %s \n", e.getZip());
-
System.out.printf("Pay is %s \n", e.getPayrate());
-
System.out.printf("Years worked are %d\n", e.getYearsworked());
-
System.out.println("--------------------");
-
}
-
}
-
}// close the displayMatch
-
-
/**
-
* @param Add
-
* a employee to the db. using a scanner to see if an
-
* Employee is in the db if no add them
-
*/
-
-
public static void main(String[] args) {
-
Employee emp = new Employee();
-
Scanner kbd = 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 = kbd.nextInt();
-
kbd.nextLine();
-
if (choice == 1) { // if 1 is select go to makePerson
-
emp.inputEmployee();
-
-
} // close the if loop
-
-
if (choice == 2) { // if 2 is select go to find
-
emp.displayMatch();
-
-
}// close the choice==2
-
if (choice == 3) {
-
System.out.printf("Good bye");
-
}// close the choice == 3
-
-
}// close public static void
-
-
}// close public class Employee
Sandyw
so near yet so far away.
I still need help see above
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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
|
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;
|
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;
| |
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...
|
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"...
|
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
*/
|
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"
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |