I know the title might not be that helpful. I do apologize. My problem is that I am trying to create a simple MPG application to help me get used to GUI. I have a gallons and a miles JTextField. I also have an ueditable JTextField to display the MPG. I am trying to convert the user input to an integer then divide the gallons and miles input for the result of the miles per gallon, which will be displayed.
I have the parseInt as displayed below:
int mil = Integer.parseInt(miles1.getText());
int gal = Integer.parseInt(gallons1.getText());
then the MPG:
int mpg = gal / mil;
It shows no error in the code, but once I go to run the application I get these errors:
java.lang.NullPointerException
at app.<init>(app.java:40)
at app$1.run(app.java:26)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Does anybody know what is causing this?