Results 1 to 4 of 4
  1. #1
    jaszczomp is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Exception in thread "AWT-EventQueue-0"

    Hello!
    I have a problem with my java application.

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class main
    {
    	public static Pole text = new Pole("0");
    	public static Przycisk plus = new Przycisk("+");
    	public static Przycisk minus = new Przycisk("-");
    	public static Przycisk dimen = new Przycisk("/");
    	public static Przycisk multi = new Przycisk("*");
    	public static Przycisk is = new Przycisk("=");
    	
    	public int l[];
    	public int i = 0;
    	public int w = 0;
    	
    	public static void main(String[] args)
    	{
    		Okno calc = new Okno("Kalkulator");
    		
    		Panel p1 = new Panel();
    		Panel p2 = new Panel();
    		Panel p3 = new Panel();
    		
    		calc.add(p1);
    		calc.add(p2);
    		calc.add(p3);
    		
    		Akcja dodaj = new Akcja_p();
    		Akcja odejmij = new Akcja_o();
    		Akcja mnoz = new Akcja_m();
    		Akcja dziel = new Akcja_d();
    		Akcja wynik = new Akcja_w();
    		
    		plus.addActionListener(dodaj);
    		minus.addActionListener(odejmij);
    		dimen.addActionListener(dziel);
    		multi.addActionListener(mnoz);
    		is.addActionListener(wynik);
    		
    		p1.add(text);
    		p2.add(plus);
    		p2.add(minus);
    		p2.add(dimen);
    		p2.add(multi);
    		p3.add(is);
    		
    		calc.setVisible(true);
    	}
    }
    
    class Okno extends JFrame
    {
    	Okno(String title)
    	{
    		setTitle(title);
    		setSize(240, 320);
    		
    		setLayout(new GridLayout(3,1));
    	}
    }
    
    class Panel extends JPanel
    {
    	Panel()
    	{
    		
    	}
    }
    
    class Przycisk extends JButton
    {
    	Przycisk(String text)
    	{
    		setText(text);
    	}
    }
    
    class Pole extends JTextField
    {
    	Pole(String def)
    	{
    		setColumns(15);
    		setText(def);
    	}
    }
    
    class Akcja implements ActionListener
    {
    	main m = new main();
    
    	public void actionPerformed(ActionEvent e)
    	{
    		
    	}
    }
    
    class Akcja_p extends Akcja
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		m.l[m.i] = Integer.parseInt(main.text.getText());
    		
    		m.w = m.w + m.l[m.i];
    		
    		main.text.setText(Integer.toString(m.w));
    		
    		m.i++;
    	}
    }
    
    class Akcja_o extends Akcja
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		
    	}
    }
    
    class Akcja_m extends Akcja
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		
    	}
    }
    
    class Akcja_d extends Akcja
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		
    	}
    }
    
    class Akcja_w extends Akcja
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		main.text.setText(Integer.toString(m.w));
    	}
    }
    After "compiling" this code, and launching app, i get following exception in console output:

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at Akcja_p.actionPerformed(main.java:104)
    	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 Source)
    	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)
    I haven't any idea, what mean this exception, i cannot see any bugs in my app. I'm still learning Java.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    at Akcja_p.actionPerformed(main.java:104)
    Look at line 104 in your program.
    Which object reference on that line is null?
    Then figure out where it should be set to some value and set it.
    If you don't see which is null, add a System.out.println() for each object reference in line 104.
    For example if the statement is: a.b.c(x) , you need to see if a or b is null:
    System.out.println("a=" + a + ", b=" + b);

  3. #3
    jaszczomp is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    when i add system.out.blah.blah, i don't get any values in console output :/

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Then your code where the println() are located is NOT executing.
    Add more println()s so you see where the code is executing. Keep adding them until you see output on the console.

Similar Threads

  1. Replies: 2
    Last Post: 12-14-2009, 01:46 AM
  2. Replies: 12
    Last Post: 10-05-2008, 06:52 AM
  3. Replies: 3
    Last Post: 01-29-2008, 01:37 AM
  4. Replies: 1
    Last Post: 08-06-2007, 06:04 PM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •