Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:33:50+00:00 2026-05-23T12:33:50+00:00

I developed an app with a GUI, with buttons, relative actionListeners, and exceptions. Today

  • 0

I developed an app with a GUI, with buttons, relative actionListeners, and exceptions.
Today I had this problem. In an actionEvent relative to a button of my GUI, I inserted this code, with some JOptionPane.showInputDialog:

public void actionPerformed(ActionEvent ae){

 if(ae.getSource()==b1){
 try{//FIRST `JOptionPane.showInputDialog`
   int load = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert current load value: "));
   auto.setCurrentLoad(load);
   //other `JOptionPane.showInputDialog`
 int choiceDep = Integer.parseInt(JOptionPane.showInputDialog(null, "Does the truck transport perishable goods? 1: YES 2: NO"));
 if(choiceDep==1) {
   //here we have to insert expiration date
   int day = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value"));
  int month = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value"));
  int year = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value"));
  auto.setPerishable(day,month,year);
 }
 else if(choiceDep==2) 
                 auto.setNotPerishable();

String choiceAv = JOptionPane.showInputDialog(null, "Available Truck? Yes or no?");
 if(choiceAv.equals("Yes")) auto.setAvailable();
 else auto.setNotAvailable();

}
        //the exception      
    catch (Exception e) { System.out.println("Exception!");}             
  }

Where setAvailable, setNotAvailable,setPerishable,setCurrentLoad are methods of the external class, with reference auto.

When I execute this code, it appears the GUI, then I click on button b1. It appears the first JOptionPane.showInputDialog, to insert a value stored in a int load.

I entered a value, but no other JOptionPane.showInputDialog appeared (but there are other input dialog) and I got the exception in the command-line.
I noticed that the value inserted in the JOptionPane.showInputDialog is never passed to the line auto.setCurrentLoad(load);.

Why does it happen? Never seen this error before. Why do I always get the exception immediately after the first JOptionPane.showInputDialog Maybe the JVM doesn’t accept many of this JOptionPane.showInputDialog in the same statement/method? Or maybe(as I think) is a programming error of mine?

Thanks for your help. Cheers.

EDIT: I forgot to insert the exception I got in the command-line:

java.lang.NullPointerException
        at AutoCom.actionPerformed(AutoCom.java:50)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown So
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:33:51+00:00Added an answer on May 23, 2026 at 12:33 pm

    Most likely, the auto object is not initialized before you pressed the button. I’m assuming auto is a member variable of the AutoCom class. In that case, you should probably change the auto definition to:

    protected <TypeOfAutoHere> auto = new <TypeOfAutoHere>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've developed an android app that's fetches an xml file and displays this data
I developed a win forms app targeting .net 2.0. All of this is in
I had developed an app in android that take some data from a database
I have current a developed app which I am going to submit in just
I have developed my app using core data. It works fine in the simulator.
I've developed an app using the 3.1.3 SDK and I want to set the
I've developed an iPhone app that has been running MPMoviePlayer (pre 3.2 SDK) with
I have developed a web app using a webservice. Everything works fine in the
I have an MVC2 app I developed with the VS2010 RC and the .NET
A few years ago I developed a web app for which we wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.