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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:02:52+00:00 2026-06-11T10:02:52+00:00

Exception in thread AWT-EventQueue-0 java.lang.ArithmeticException: / by zero at factoroperations.compute(factoroperations.java:21) at factorframe$buttonhandler.actionPerformed(factorframe.java:71) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20

  • 0
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero
        at factoroperations.compute(factoroperations.java:21)
        at factorframe$buttonhandler.actionPerformed(factorframe.java:71)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
18)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2341)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6504)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6269)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4860)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4686)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2713)
        at java.awt.Component.dispatchEvent(Component.java:4686)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo


main.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:680)
        at java.awt.EventQueue$4.run(EventQueue.java:678)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
//Project: A program that factors numbers

//This defines the properties of the user interface

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;

public class factorframe extends JFrame
{//declare all the variables
    private JLabel integerlabel;
    private JTextField integerfield;
    private JLabel factorslabel;
    private JTextField factorsfield;
    private JLabel namelabel;
    private JButton computebutton;
    private JButton clearbutton;
    private JButton exitbutton;
    private String integerstring;
    private long integer;
    private String factorsstring;
    private int factors;
    private factoroperations factormachine;

 public factorframe() //This is the constructor
 {  //add all buttons and fields
    super("Factor Frame");
    setLayout(new FlowLayout());
    namelabel = new JLabel("Integer Factorization  By Michael Daigh");
    add(namelabel);
    integerlabel = new JLabel("Enter an integer:");
    add(integerlabel);
    integerfield = new JTextField(20);
    add(integerfield);
    factorslabel = new JLabel("The factors are:");
    add(factorslabel);
    factorsfield = new JTextField(20);
    add(factorsfield);
    computebutton = new JButton("Compute Factors");
    add(computebutton);
    clearbutton = new JButton("Clear");
    add(clearbutton);
    exitbutton = new JButton("Exit");
    add(exitbutton);
    buttonhandler myhandler = new buttonhandler();
    computebutton.addActionListener(myhandler);
    clearbutton.addActionListener(myhandler);
    exitbutton.addActionListener(myhandler);
    factormachine = new factoroperations();
 }//End of constructor method
 private class buttonhandler implements ActionListener
   {public void actionPerformed(ActionEvent event)
        {
            if(event.getSource() == computebutton)//if user clicks compute factors
            {//computes the factors of the number
                integerstring = integerfield.getText();//get the number
                integer = Long.parseLong(integerstring);
                factorsstring = factoroperations.compute(integer);
                factorsfield.setText(factorsstring);//display the factors
            }
            else if(event.getSource() == clearbutton)//if user clicks clear
            {//clears all data in integer field and factor field
                integer=0;
                integerfield.setText("");
                factors=0;
                factorsfield.setText("");
            }
            else if(event.getSource() == exitbutton)//if user clicks exit
            {//exits the program
                System.exit(0);
            }
            else
                System.out.println("Unknown error");
        }//End of actionPerformed
    }//End of buttonhandler class
}//End of factorframe class


//Project: A program that factors numbers

//This contains the algorithm used by this project.

public class factoroperations
{
 public static String compute(long integer)
 {
    String factor="";//initialize the factor string
    int check = 1;//initialize the prime check
    for(int i=2; i<=integer/2; i++)
    {
        if(integer%i==0)//i is a factor of the number
        {
            for(int k=2; k<i; k++)//check if it is prime
            {
                if(i%k ==0)
                {
                    check = 1;
                    break;
                }
                else
                    check = 0;
            }
            if(check == 0 || i == 2)//display the prime factors only
            {
                factor = factor + " " + i + "P";
            }
            else if(check == 1)//display all other factors
                factor = factor + " " + i;
        }
    }
    if(factor == "")//if number does not factor, it is already prime
    {
        factor = "No factors. It is a prime number";
    }
    return factor;
 }
}//End factoroperations class


//Project: A program that factors numbers

//This activates the user interface.
import javax.swing.JFrame;
public class testfactor
{public static void main(String[] args)
    {factorframe myframe = new factorframe();
     myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     myframe.setSize(325,225);
     myframe.setVisible(true);
    }//End of main
}//End of class testfactor
  • 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-11T10:02:53+00:00Added an answer on June 11, 2026 at 10:02 am

    You’re getting int overflow and are dividing by 0. While the integer parameter is a long, your i is an int and it will overflow if it tries to increment to match the size of the large long parameter, and when it overflows, its value can be 0, negative, or lord knows what.

    One possible solution: your for loop indices should both be longs, not ints.

    Also, for what it’s worth, it’s quite confusing giving a long parameter or variable the name integer!

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

Sidebar

Related Questions

I'm getting the following NullPointerException: Exception in thread AWT-EventQueue-0 java.lang.NullPointerException at com.foo.JawsFileChooser.a(SourceFile:28) at com.foo.JawsFileChooser$1.actionPerformed(SourceFile:91)
Exception in thread AWT-EventQueue-0 java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source)
I am having a runtime error that states Exception in thread AWT-EventQueue-0 java.lang.NullPointerException at
Why do I get a Exception in thread AWT-EventQueue-0 java.lang.OutOfMemoryError: Java heap space because
I get this exception: Exception in thread AWT-EventQueue-0 java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2882)
Im getting Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException:0 and I really dont understand why. I
I am getting the following exception Exception in thread AWT-EventQueue-0 java.lang.NullPointerException at Java.CompileFile.doCompilation(CompileFile.java:48) at
Here is the exception I am getting: Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException: 20203 at
Exception in thread main java.lang.NullPointerException at Library.loadBooks(Library.java:179) at UseLibrary.main(UseLibrary.java:105) This error makes me crazy!
Exception in thread Thread-0 java.lang.NullPointerException at org.apache.http.impl.nio.reactor.AbstractIOReactor.closeActiveChannels(AbstractIOReactor.java:532) at org.apache.http.impl.nio.reactor.AbstractIOReactor.hardShutdown(AbstractIOReactor.java:564) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.doShutdown(AbstractMultiworkerIOReactor.java:411) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:340) at

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.