i built a little software. The software runs perfectly ok as it should. On initiation of the software, a option pane pops up asking for name, user can insert name then choose ok or just cancel and terminate the running software. my issue with this now is that if the user clicks the cancel option it terminates then throws a bunch of errors. These errors i do not understand, I've used the appropriate exception for almost every method I've created. Does anybody have any advice or idea of whats going on.
This is the RequestAngentName Class
public class RequestAgentName{
// instance variable daclaration
private static String uName;
/*
recursive method set username to instance variable
*/
public void setUserName(String name) throws NullPointerException
{
name = JOptionPane.showInputDialog(null, "Insert First Name and Last Initial", "Agent Name",
JOptionPane.PLAIN_MESSAGE);
// if user input is not empty
(line 24)if(!name.isEmpty())
{
// verify input is acceptable, if yes assign input to global variable
if(JOptionPane.showConfirmDialog(null, "Is This Your Name?\n\n " + name, "WARNING" , JOptionPane.YES_NO_OPTION) == JOptionPane.YES_NO_OPTION)
{
uName = name;
} // end if
// if input is not acceptable prompt user to reenter name
else
// if username is wrong reenter until correct
this.setUserName(name);
} // end if
// if input is empty prompt user to reenter
else
this.setUserName(name);
} //end method set username
// method to return user input
public String getUserName(){
return uName;
} // end method get username
} // end of Request name class
This is how i invoked it in main, which i feel could be where the error is to
RequestAgentName userName = new RequestAgentName();
try {
(line 52) userName.setUserName(userName.getUserName());
new FNAFrame();
(new Thread(new FnaComponents())).start();
}
catch (NullPointerException npe){
npe.printStackTrace();
}
The errors are as follows;
java.lang.NullPointerException
at fna.comments.generator.RequestAgentName.setUserName(RequestAgentName.java:24)
at fna.comments.generator.FNAFrame$1.run(FNAFrame.java:52)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 6 seconds)