SlideShare a Scribd company logo
1 of 7
Download to read offline
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.pdfasarudheen07
 
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.pdfAnkitchhabra28
 
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.pdfmail931892
 
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.pdfarrowmobile
 
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.pdfaksahnan
 
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.pdfpritikulkarni20
 
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.pdfarishmarketing21
 
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.pdfmail931892
 
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.pdfmichardsonkhaicarr37
 
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.pdfalmaniaeyewear
 
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 .pdfsiennatimbok52331
 
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.pdfNicholasflqStewartl
 
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.pdffantasiatheoutofthef
 
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.pdffathimafancyjeweller
 
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..pdfferoz544
 
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.pdfkostikjaylonshaewe47
 
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.pdfallystraders
 
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.pdfChristopherkUzHunter
 
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.pdfmallik3000
 
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.pdfStewart29UReesa
 

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.pdfpnaran46
 
L-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdfL-{anbmcmdnn-m0} (1).pdf
L-{anbmcmdnn-m0} (1).pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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.pdfpnaran46
 
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-.pdfpnaran46
 
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.pdfpnaran46
 

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

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .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; } }