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 7753061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:57:29+00:00 2026-06-01T11:57:29+00:00

I have as a task to simulate how queues evolve in a supermarket and

  • 0

I have as a task to simulate how queues evolve in a supermarket and I have to use timers to output whenever a client enters or exists the store. In the supermarket I have 3 queues that should process customers. At each client, they should output in my GUI the arrival time and the leaving time. Can I use the same timer for each queue? (they should not start outputting simultaneously or for the same period of time). I tried to pass the timer as a parameter in the event class but I get a Null Pointer exception. Help pls.

  public void simulationPrep (Queue q,JPanel p,int time,Timer t, int selection)

  {

    TimeClass tc;
    int queueCapacity=0;
    float queueProcTime=0;
    float tempSTMin, float tempSTMax;
    tempSTMin=getServiceTimeMin();
    tempSTMax=getServiceTimeMax();
    queueCapacity = 10 + (int)( Math.random()*20);
    queueProcTime = tempSTMin + (float)(Math.random()*tempSTMax);
    q1.setCapacity(queueCapacity);
    q1.setProcessingTime(queueProcTime);
    tc = new TimeClass((int)(queueProcTime/queueCapacity),p,selection);
    t = new Timer(time, tc);
    t.start();
}
public void simulate()
{
    if(getSelection()>=1)
    {
        simulationPrep(q1,p21,1000,timer1,1);
        if(getSelection()>=2)
        {
            simulationPrep(q2,p22,1500,timer2,2);
            if(getSelection()==3)
            {
                simulationPrep(q3,p23,1700,timer3,3);
            }
        }
    }

}

public class TimeClass implements ActionListener
{
    int counter;
    JPanel p;
    int selection;
    public TimeClass(int counter,JPanel p,int selection)
    {
        this.counter = counter;
        this.p = p;
        this.selection = selection;
    }
    public void actionPerformed(ActionEvent e)
    {
        counter--;
        if(counter>=1)
        {
            p.add(new JLabel("Hi "+counter));
            p.updateUI();
        }
        if(counter<1)
        {
            p.add(new JLabel("Done"));
            p.updateUI();
            timer1.stop();
            timer2.stop();
            timer3.stop();
        }
    }
}

If one does not understand the code please ask, I’ll be more specific, but this is my first post here and I’m kind of new to Java.

This is what I get in the output window :

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at simulation.Simulation$TimeClass.actionPerformed(Simulation.java:229)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at simulation.Simulation$TimeClass.actionPerformed(Simulation.java:229)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)
  • 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-06-01T11:57:31+00:00Added an answer on June 1, 2026 at 11:57 am

    Line 229 of your Simulation.java file is causing a NullPointerException. Specifically it is in the actionPerformed(…) method of your TimeClass inner class.

    Go to that line, and there you’ll have your problem.

    I suspect it is one of these 3 lines:

            timer1.stop();
            timer2.stop();
            timer3.stop();
    

    One of these timer variables is probably null.

    A quick fix (although probably not addressing the real problem) is this:

    if (timer1 != null) {
        timer1.stop();
    }
    

    and so on with the other two timer variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have task involving reading SAS .xpt files using .NET. For that I'm using
I have a Task object that has a collection of Label objects ... in
I have task to give in my application possibility to open document that is
I have task schedule for backup directory list of wwwroot. For that I have
I have a task that is not important ; it should be run once
I have a task to store large amount of gps data and some extra
Say that I have two resources, Project and Task. A Project can have many
We have an EPOS system that is built in VB6. A client is using
I have task queue that adds task to second queue, while second queue is
i have task which takes a parameter and has three modes of results Example

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.