SlideShare a Scribd company logo
How do I fix this error "
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.hashCode()"
because "action" is null
at AddressBook.main(AddressBook.java:25)"
import java.util.Scanner;
public class AddressBook {
public static void main(String[] args) {
Tablea addressBook = new Tablea();
Scanner scanner = new Scanner(System.in);
String name, address;
String action = null;
boolean moreEntries = true;
while (moreEntries) {
System.out.println("/nMenu");
System.out.println("n.Add Entry");
System.out.println("d. Delete Entry");
System.out.println("u. Update Entry");
System.out.println("l. Search");
System.out.println("a. View All");
System.out.println("q. Exit");
// Insert a new entry into the address book
switch (action) {
case "n":
System.out.print("Enter a name: ");
name = scanner.nextLine();
System.out.print("Enter an address: ");
address = scanner.nextLine();
addressBook.insert(name, address);
System.out.println("New Contact has been added,");
System.out.print("Add another entry? (y/n): ");
String answer = scanner.nextLine().toLowerCase();
moreEntries = answer.equals("y") || answer.equals("yes");
break;
// Delete an entry from the address book
case "d":
System.out.println("Enter a name to delete: ");
name = scanner.nextLine();
boolean deleted = addressBook.delete(name);
if (deleted) {
System.out.println("Address deleted");
} else {
System.out.println("Name not found");
}
break;
// Update an entry in the address book
case "u":
System.out.print("Enter a name to update: ");
name = scanner.nextLine();
System.out.print("Enter a new address: ");
address = scanner.nextLine();
boolean updated = addressBook.update(name, address);
if (updated) {
System.out.println("Address updated");
} else {
System.out.println("Name not found");
}
break;
// Lookup an entry in the address book
case "l":
System.out.print("Enter a name to look up: ");
name = scanner.nextLine();
String result = addressBook.lookUp(name);
if (result != null) {
System.out.println("Address: " + result);
} else {
System.out.println("Name not found");
}
break;
// Display all entries in the address book
case "a":
System.out.println("All entries:");
addressBook.displayAll();
break;
// Quit the program
case"q":
System.out.println("Quitting...");
}
}
}
}
Other files that go with it
public class Node {
private String name;
private String address;
private Node next;
Node() {
// add here ..
}
Node(String name, String address) {
// add here ..
this.name = name;
this.address = address;
this.next = null;
}
public String getKey() {
// add here ..
return this.name;
}
public void setKey(String name) {
// add here ..
this.name = name;
}
public String getValue() {
// add here ..
return this.address;
}
public void setValue(String address) {
// add here ..
this.address = address;
}
public Node getNext() {
// add here ..
return this.next;
}
public void setNext(Node next) {
// add here ..
this.next = next;
}
}
import java.util.Scanner;
public class Tablea {
private Node mark;
public Node getMark() {
return this.mark;
}
public void setMark(Node mark) {
this.mark = mark;
}
public boolean insert(String name, String address) {
Node newNode= new Node(name,address);
if (this.mark== null) {
this.mark = newNode;
}else {
newNode.setNext(this.mark.getNext());
this.mark.setNext(newNode);
}
return true;
}
public String lookUp(String name) {
Node current = this.mark;
while(current!=null) {
if (current.getKey().equals(name)) {
return current.getValue();
}
current = current.getNext();
}
return null;
}
public boolean delete(String name) {
Node current = this.mark;
Node prev = null;
while (current!= null) {
if (current.getKey().equals(name)) {
if (prev == null) {
this.mark = current.getNext();
}else {
prev.setNext(current.getNext());
}
return true;
}
prev = current;
current = current.getNext();
}
return false;
}
public boolean update(String name, String newValue) {
Node current = this.mark;
while (current != null) {
if (current.getKey().equals(name)) {
current.setValue(newValue);
return true;
}
current = current.getNext();
}
return false;
}
public boolean markToStart() {
if (this.mark== null) {
return false;
}
this.mark = null;
return true;
}
public boolean advanceMark() {
if (this.mark== null) {
return false;
}
this.mark = this.mark.getNext();
return true;
}
public String keyAtMark() {
if (this.mark== null) {
return null;
}
return this.mark.getKey();
}
public String valueAtMark() {
if (this.mark== null) {
return null;
}
return this.mark.getValue();
}
public int displayAll() {
Node current = this.mark;
int count = 0;
while (current != null) {
System.out.println(current.getKey()+":"+ current);
}
return count;
}
}
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf

More Related Content

Similar to How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf

import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
Ankitchhabra28
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
aksahnan
 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
pritikulkarni20
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
arishmarketing21
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
siennatimbok52331
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
NicholasflqStewartl
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
feroz544
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
allystraders
 
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- {   privat.pdfpublic class CircularDoublyLinkedList-E- implements List-E- {   privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
ChristopherkUzHunter
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 

Similar to How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf (20)

import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdfHi, Please find my code.I have correted all of your classes.Plea.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- {   privat.pdfpublic class CircularDoublyLinkedList-E- implements List-E- {   privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 

More from pnaran46

John works as a goldsmith who often repairs jewellry- Maria brought in.pdf
John works as a goldsmith who often repairs jewellry- Maria brought in.pdfJohn works as a goldsmith who often repairs jewellry- Maria brought in.pdf
John works as a goldsmith who often repairs jewellry- Maria brought in.pdf
pnaran46
 
L-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdfL-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdf
pnaran46
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
pnaran46
 
Given that x has a Poitson destribition with -1-7- what is the poobati.pdf
Given that x has a Poitson destribition with -1-7- what is the poobati.pdfGiven that x has a Poitson destribition with -1-7- what is the poobati.pdf
Given that x has a Poitson destribition with -1-7- what is the poobati.pdf
pnaran46
 
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdf
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdfFind the p-value using Excel (not Appendix D)- (Round your answers to.pdf
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdf
pnaran46
 
Apple Inc- had gone through a hard period in the early 90s and almost.pdf
Apple Inc- had gone through a hard period in the early 90s and almost.pdfApple Inc- had gone through a hard period in the early 90s and almost.pdf
Apple Inc- had gone through a hard period in the early 90s and almost.pdf
pnaran46
 
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
pnaran46
 
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdfa- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
pnaran46
 
57) All of the following are non-arguments except- a- Americans are ma.pdf
57) All of the following are non-arguments except- a- Americans are ma.pdf57) All of the following are non-arguments except- a- Americans are ma.pdf
57) All of the following are non-arguments except- a- Americans are ma.pdf
pnaran46
 
2- An instructor wishes to see whether the variation in scores of the.pdf
2- An instructor wishes to see whether the variation in scores of the.pdf2- An instructor wishes to see whether the variation in scores of the.pdf
2- An instructor wishes to see whether the variation in scores of the.pdf
pnaran46
 
You are working as the chief economist for the Ministry of Economy in.pdf
You are working as the chief economist for the Ministry of Economy in.pdfYou are working as the chief economist for the Ministry of Economy in.pdf
You are working as the chief economist for the Ministry of Economy in.pdf
pnaran46
 
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdfThe Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
pnaran46
 
The supply of low-skilled workers in China is perfectly elastic- In 20.pdf
The supply of low-skilled workers in China is perfectly elastic- In 20.pdfThe supply of low-skilled workers in China is perfectly elastic- In 20.pdf
The supply of low-skilled workers in China is perfectly elastic- In 20.pdf
pnaran46
 
The Federal Reserve provides accounts to financial institutions only f.pdf
The Federal Reserve provides accounts to financial institutions only f.pdfThe Federal Reserve provides accounts to financial institutions only f.pdf
The Federal Reserve provides accounts to financial institutions only f.pdf
pnaran46
 
The following is the balance sheet numbers (in millions) reported by B.pdf
The following is the balance sheet numbers (in millions) reported by B.pdfThe following is the balance sheet numbers (in millions) reported by B.pdf
The following is the balance sheet numbers (in millions) reported by B.pdf
pnaran46
 
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
pnaran46
 
Singh Company reports a contribution margin of $717-000 and fixed cost.pdf
Singh Company reports a contribution margin of $717-000 and fixed cost.pdfSingh Company reports a contribution margin of $717-000 and fixed cost.pdf
Singh Company reports a contribution margin of $717-000 and fixed cost.pdf
pnaran46
 
Provide an appropriate response- How many ways can five people- A- B-.pdf
Provide an appropriate response- How many ways can five people- A- B-.pdfProvide an appropriate response- How many ways can five people- A- B-.pdf
Provide an appropriate response- How many ways can five people- A- B-.pdf
pnaran46
 
QRT Soltware creates and distributes inventory control noftware- The h.pdf
QRT Soltware creates and distributes inventory control noftware- The h.pdfQRT Soltware creates and distributes inventory control noftware- The h.pdf
QRT Soltware creates and distributes inventory control noftware- The h.pdf
pnaran46
 

More from pnaran46 (19)

John works as a goldsmith who often repairs jewellry- Maria brought in.pdf
John works as a goldsmith who often repairs jewellry- Maria brought in.pdfJohn works as a goldsmith who often repairs jewellry- Maria brought in.pdf
John works as a goldsmith who often repairs jewellry- Maria brought in.pdf
 
L-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdfL-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdf
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
 
Given that x has a Poitson destribition with -1-7- what is the poobati.pdf
Given that x has a Poitson destribition with -1-7- what is the poobati.pdfGiven that x has a Poitson destribition with -1-7- what is the poobati.pdf
Given that x has a Poitson destribition with -1-7- what is the poobati.pdf
 
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdf
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdfFind the p-value using Excel (not Appendix D)- (Round your answers to.pdf
Find the p-value using Excel (not Appendix D)- (Round your answers to.pdf
 
Apple Inc- had gone through a hard period in the early 90s and almost.pdf
Apple Inc- had gone through a hard period in the early 90s and almost.pdfApple Inc- had gone through a hard period in the early 90s and almost.pdf
Apple Inc- had gone through a hard period in the early 90s and almost.pdf
 
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
6) Cytological mapping (4 points) i) Deletional-deficiency-ii) Duplica.pdf
 
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdfa- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
a- Let- a host with IP address 10-0-0-10-3550 want to transmit 16 bit.pdf
 
57) All of the following are non-arguments except- a- Americans are ma.pdf
57) All of the following are non-arguments except- a- Americans are ma.pdf57) All of the following are non-arguments except- a- Americans are ma.pdf
57) All of the following are non-arguments except- a- Americans are ma.pdf
 
2- An instructor wishes to see whether the variation in scores of the.pdf
2- An instructor wishes to see whether the variation in scores of the.pdf2- An instructor wishes to see whether the variation in scores of the.pdf
2- An instructor wishes to see whether the variation in scores of the.pdf
 
You are working as the chief economist for the Ministry of Economy in.pdf
You are working as the chief economist for the Ministry of Economy in.pdfYou are working as the chief economist for the Ministry of Economy in.pdf
You are working as the chief economist for the Ministry of Economy in.pdf
 
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdfThe Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
The Taylors agreed to make monthly payments on a mortgage of $130-000.pdf
 
The supply of low-skilled workers in China is perfectly elastic- In 20.pdf
The supply of low-skilled workers in China is perfectly elastic- In 20.pdfThe supply of low-skilled workers in China is perfectly elastic- In 20.pdf
The supply of low-skilled workers in China is perfectly elastic- In 20.pdf
 
The Federal Reserve provides accounts to financial institutions only f.pdf
The Federal Reserve provides accounts to financial institutions only f.pdfThe Federal Reserve provides accounts to financial institutions only f.pdf
The Federal Reserve provides accounts to financial institutions only f.pdf
 
The following is the balance sheet numbers (in millions) reported by B.pdf
The following is the balance sheet numbers (in millions) reported by B.pdfThe following is the balance sheet numbers (in millions) reported by B.pdf
The following is the balance sheet numbers (in millions) reported by B.pdf
 
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
1) Ludwig von Mises (1871 - 1973) was an influential economist from Au.pdf
 
Singh Company reports a contribution margin of $717-000 and fixed cost.pdf
Singh Company reports a contribution margin of $717-000 and fixed cost.pdfSingh Company reports a contribution margin of $717-000 and fixed cost.pdf
Singh Company reports a contribution margin of $717-000 and fixed cost.pdf
 
Provide an appropriate response- How many ways can five people- A- B-.pdf
Provide an appropriate response- How many ways can five people- A- B-.pdfProvide an appropriate response- How many ways can five people- A- B-.pdf
Provide an appropriate response- How many ways can five people- A- B-.pdf
 
QRT Soltware creates and distributes inventory control noftware- The h.pdf
QRT Soltware creates and distributes inventory control noftware- The h.pdfQRT Soltware creates and distributes inventory control noftware- The h.pdf
QRT Soltware creates and distributes inventory control noftware- The h.pdf
 

Recently uploaded

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 

How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf

  • 1. How do I fix this error " Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "action" is null at AddressBook.main(AddressBook.java:25)" import java.util.Scanner; public class AddressBook { public static void main(String[] args) { Tablea addressBook = new Tablea(); Scanner scanner = new Scanner(System.in); String name, address; String action = null; boolean moreEntries = true; while (moreEntries) { System.out.println("/nMenu"); System.out.println("n.Add Entry"); System.out.println("d. Delete Entry"); System.out.println("u. Update Entry"); System.out.println("l. Search"); System.out.println("a. View All"); System.out.println("q. Exit"); // Insert a new entry into the address book switch (action) { case "n": System.out.print("Enter a name: "); name = scanner.nextLine(); System.out.print("Enter an address: "); address = scanner.nextLine(); addressBook.insert(name, address); System.out.println("New Contact has been added,"); System.out.print("Add another entry? (y/n): "); String answer = scanner.nextLine().toLowerCase(); moreEntries = answer.equals("y") || answer.equals("yes");
  • 2. break; // Delete an entry from the address book case "d": System.out.println("Enter a name to delete: "); name = scanner.nextLine(); boolean deleted = addressBook.delete(name); if (deleted) { System.out.println("Address deleted"); } else { System.out.println("Name not found"); } break; // Update an entry in the address book case "u": System.out.print("Enter a name to update: "); name = scanner.nextLine(); System.out.print("Enter a new address: "); address = scanner.nextLine(); boolean updated = addressBook.update(name, address); if (updated) { System.out.println("Address updated"); } else { System.out.println("Name not found"); } break; // Lookup an entry in the address book case "l": System.out.print("Enter a name to look up: "); name = scanner.nextLine(); String result = addressBook.lookUp(name); if (result != null) { System.out.println("Address: " + result); } else {
  • 3. System.out.println("Name not found"); } break; // Display all entries in the address book case "a": System.out.println("All entries:"); addressBook.displayAll(); break; // Quit the program case"q": System.out.println("Quitting..."); } } } } Other files that go with it public class Node { private String name; private String address; private Node next; Node() { // add here .. } Node(String name, String address) { // add here .. this.name = name; this.address = address; this.next = null; } public String getKey() { // add here .. return this.name; }
  • 4. public void setKey(String name) { // add here .. this.name = name; } public String getValue() { // add here .. return this.address; } public void setValue(String address) { // add here .. this.address = address; } public Node getNext() { // add here .. return this.next; } public void setNext(Node next) { // add here .. this.next = next; } } import java.util.Scanner; public class Tablea { private Node mark; public Node getMark() { return this.mark; } public void setMark(Node mark) { this.mark = mark; } public boolean insert(String name, String address) { Node newNode= new Node(name,address); if (this.mark== null) { this.mark = newNode; }else {
  • 5. newNode.setNext(this.mark.getNext()); this.mark.setNext(newNode); } return true; } public String lookUp(String name) { Node current = this.mark; while(current!=null) { if (current.getKey().equals(name)) { return current.getValue(); } current = current.getNext(); } return null; } public boolean delete(String name) { Node current = this.mark; Node prev = null; while (current!= null) { if (current.getKey().equals(name)) { if (prev == null) { this.mark = current.getNext(); }else { prev.setNext(current.getNext()); } return true; } prev = current; current = current.getNext(); } return false; } public boolean update(String name, String newValue) { Node current = this.mark; while (current != null) { if (current.getKey().equals(name)) { current.setValue(newValue); return true; } current = current.getNext(); } return false; }
  • 6. public boolean markToStart() { if (this.mark== null) { return false; } this.mark = null; return true; } public boolean advanceMark() { if (this.mark== null) { return false; } this.mark = this.mark.getNext(); return true; } public String keyAtMark() { if (this.mark== null) { return null; } return this.mark.getKey(); } public String valueAtMark() { if (this.mark== null) { return null; } return this.mark.getValue(); } public int displayAll() { Node current = this.mark; int count = 0; while (current != null) { System.out.println(current.getKey()+":"+ current); } return count; } }