NullPointerException « Development « Java Swing Q&A





1. What's wrong with this code?    stackoverflow.com

I wrote this code:

public class FileViewer extends JPanel implements ActionListener {

/**
 * 
 */
private static final long serialVersionUID = 1L;

JFileChooser chooser;

FileNameExtensionFilter filter = null;

JEditorPane pane = null;

JTextField text = null;

JButton button;

JTextArea ...

2. Java - NullPointerException at start. Swing bug or faulty implementation?    stackoverflow.com

I am developing an application for a company, which manages an oracle database in various ways. The program is in Java, NetBeans and it is getting pretty big. I wouldn't say it's very ...

3. Why am I getting a NullPointerException when creating a Swing component?    stackoverflow.com

The error occurs when creating the Box object.

    public void drawBoard(Board board){
    for(int row = 0; row < 8; row++){
      ...

4. Cannot find the source of a nullPointerException    stackoverflow.com

I am trying to make a simple GUI, but am running into some errors. I want to create 3 simple buttons, and have them display side by side, the length of ...

5. NullPointerException at javax.swing.plaf.synth.SynthContext.getPainter    stackoverflow.com

A Java Swing program I work on keeps getting the exception below. It happens at random times and is far from reproducible. It does not seem to usually cause any problem ...

6. Swing - NullPointerException related to File    stackoverflow.com

Working from this example, I'm trying to break up the logic from the swing elements initialization and actios, while trying retrieve some information from the fileChooser, for other purposes. ...

7. Components not initialized throwing NUllPointerException    stackoverflow.com

Please help me figure out what is going wrong here? just starting out in java.

public class PropertyChangeListenerTest {
private JPanel mainPanel = null;
private JTextField source = null;
private JTextField target = null;

PropertyChangeListenerTest() {

 ...

8. Java null pointer exception wont terminate program    stackoverflow.com

my question is simple. How to force JAVA to terminate the program I am writing when any Exception occures? I am currenlty using Swing and when a NullPointer exception is thrown, the ...

9. Java: NullPointerException caused by class definition?    stackoverflow.com

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)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    [...snip...]
when users click a ...





10. how to solve NullPointerException in java swing    bytes.com

P: 1 senthilaim import javax.swing.*; import java.awt.*; public class RegionFrame extends JFrame { JLabel lblRegName=null; JLabel lblDistName=null; JLabel lblRegionForm=null; JLabel lblStatName=null; JTextField txtRegName=null; JTextField txtDistName=null; JButton butAdd=null; JButton butUpdate=null; JComboBox cmbSta=null; ...

11. Java GUI Static component, NullPointerException    bytes.com

I can't cause of the classic bull#*$@#* of java. initComponents isn't static and I can't call it in static main.. I tried what you suggested before though. treePanel=new JPanel(); before run() ...

12. NullPointerException in my First AWT program    coderanch.com

I am getting NullPointerException... import java.awt.*; import java.awt.event.* ; import java.util.*; class Hang1 { private Frame f ; private Button[] but; private Panel pn , pc ; static private String[] keys = { "A" , "B" , "C" , "D" , "E" ,"F" ,"G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "V" , ...

13. Cannot isolate this NullPointerException    coderanch.com

I have a class Grapher2.java that I'm trying to remodel so that it is more OO and less procedural. The other related classes are Graph2.java & GraphFrame2.java, though I'm getting the NullPointerException from class Grapher2.java. I know that they aren't a very good representation of OOP, but does anyone see where I am messing up?? I thought I was doing something ...

14. Perplexing NullPointerException    coderanch.com

Has anyone encountered this problem before? This happens occasionally (not very often, but once is more often than it should be) and stems from a call to the setVisible() method of my main application JFrame. Any clue as to why this happens sometimes and not others? It's obviously a Swing thread issue, but I haven't been able to figure out why ...

15. NullPointerException: peer    coderanch.com

16. Why NullPointerException?    coderanch.com

I am getting the following "NullpointerException" in my application at some point of time. I am unable to backtrack or trace or catch the exception. It doesn't occur everytime and the error is not giving the line number also. Can anyone give me a clue to find this. Thanx in advance. ~Visu Error details: java.lang.NullPointerException at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source) ...





18. NullPointerException    coderanch.com

Hi all, Thanks for all your help in previous post, but now I'm really stumped on what to do. There seems to be a runtime error like so: java.lang.NullPointerException at MonopolyTester$SettingsFrame.(MonopolyTester.java:58) at MonopolyTester.init(MonopolyTester.java:26) at sun.applet.AppletPanel.run(AppletPanel.java:353) at java.lang.Thread.run(Thread.java:534) And here's my code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MonopolyTester extends javax.swing.JApplet { //INITIALIZING PANELS BoardPane bp; EventPane ep; CurrentPlayerPane cpp; ...

19. NullPointerException in FlowView.changedUpdate()    coderanch.com

Here's the Java API code (javax.swing.text.FlowView) that gives me the NPE: /** * Gives notification from the document that attributes were changed * in a location that this view is responsible for. * * @param changes the change information from the associated document * @param a the current allocation of the view * @param f the factory to use to rebuild ...

20. NullPointerException at BasicTableUI$MouseInputHandle    coderanch.com

Hi, I'm using a Jtable and adding certain custom components to it. I get the following NullpointerException when I click on cell which has the custom component(A JPanel with a list dropdown). But if I tab to that particular cell and then click with the mouse I don't find the NullpointerException. EXCEPTION: java.lang.NullPointerException at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.setDispatchComponent(BasicTableUI.java:461) at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.adjustFocusAndSelection(BasicTableUI.java:511) at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(BasicTableUI.java:494) at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:221) ...

21. Null pointer Exception in Basic List UI    coderanch.com

Hello All I am facing a problem in Javax swing while painting GUI. I am showing a dialog by using SwingUtilities.invokeLater() and some processing is done in background and based upon that I am updating my GUI in background. After the painting and updating in background is complete I remove the dialog. But in the meantime the following exception is coming. ...

22. getting NullPointerException    coderanch.com

23. getting NullPointerException    coderanch.com

24. Tricky NullPointerException Problem    coderanch.com

25. Null Pointer Exception    coderanch.com

26. Getting NullPointerException    coderanch.com

Hi, I have been working with eclipse from the last week. It was all working fine.I was doing small example programs.Yesterday when I ran a program I got this NullPointerException.I tried to see if I had done any mistake in the coding...but it was all fine, moreover all my old programs which were working fine are also showing the same error ...

27. Null pointer exception.....    coderanch.com

28. NullPointerException    coderanch.com

Hi, In my program i don't have any errors while compiling but i am getting this error while compiling: "Exception in thread "main" java.lang.NullPointerException at library.(library.java:205) at library.main(library.java:515) Press any key to continue..." The program code is below starting from the line number 205 as indicated in error " find.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Vector columnNames = new ...

30. NullPointerException thrown when generating SWING GUI    coderanch.com

Hi there folks, I am currently writing a small application that is used to demonstrate multi threading in a Swing-based interface application. The Main method initialises an array of objects, a couple of DefaultListModels with another set of assigned objects. I have then passed these parameters to an instance of another type of GUI class, generated by a simple new() GUIClass ...

32. AWT-EventQueue-0" java.lang.NullPointerException: component argument pData    coderanch.com

I have old code that was written in awt and ran great in JRE 1.3. Then JRE 1.4 had some problems - which I cannot remember now, so we continued to use JRE 1.3. Lo and behold, our awt problems have gone away with JRE 1.5, but a new problwm has cropped up. When the applet closes, I get the following ...

33. Program throws a NullPointerException when we setNominalViewingTrasform    coderanch.com

The following code is supposed to create a Cylinder object and add it to the scenegraph. The radius and height for the Cylinder object are provided using a dialog box, so when the input is entered a Cylinder with the set parameters should appear on the canvas. import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.lang.String; import com.sun.j3d.utils.geometry.Cylinder; ...

34. getGraphics returnning null pointer exception    coderanch.com

Hi, i'm trying to make a program to display mandelbrot and julia set, i already have the methods to determine weather a point is in the set or not for both, the problem comes when trying to display, my code is this: /* * juliabrot.java * * */ package Fractales; import java.awt.Color; import java.awt.Graphics; /** * * */ public class juliabrot ...

35. null pointer exception    coderanch.com

i am making a prog to enter values in a textfield array and sum all those values but i am getting null pointer exception when i click on sum button and clear button please help me out import java.awt.*; import java.applet.*; import java.awt.event.*; // public class M extends Applet implements ActionListener { Button sum; Button avg; Button clear; static final ...

36. NullPointerException on swing    coderanch.com

I believe this is my first post here in the ranch so let me start this by saying hello to you all! Alright on topic, the below is supposed to be the main page for a class project i'm currently working on. I actually based the this code on an example from a book i'm reading. But then when i tried ...

37. why am i getting a null pointer exception    coderanch.com

Hi guys budsy again , getting a problem in this code .I am taking two radio buttons and adding it to a buttongroup . Then i run System.out.println() to see the values but im getting a null pointer exception . I have used a similar code but in that i didn't get any error. Please help import javax.swing.*; import java.awt.*; public ...

38. Null Pointer Exception in a GUI application    coderanch.com

Hi Guys, i would like to extend this question by asking something about my code. i'm basically attempting to use extended JFrame (to understand how it differs) but i've run into a problem. i decided to post the code so it makes more sense: package org.javaguitutorial.gui; import javax.swing.*; import java.awt.*; public class FirstGUI extends JFrame { private JButton button1,button2,button3; private JPanel ...

39. Null Pointer Exception in a GUI application (2)    coderanch.com

An application is not a JFrame and it never will be. In my mind, the JFrame models the outermost rim of the application (like the frame of a picture), and only includes the system menu, the state buttons; it has a dimension and it holds the various panels the application may make use of. It also does all of this just ...

40. NullPointerException issue    java-forums.org

I am hoping someone can help me out here. I am trying to run an example provided by an instructor and I am not able to get it running properly. The input is console based, should be able to enter 1, 2, or 3 but when I enter any number other than 1, I am getting the following error message: Exception ...

41. Integration Problem-Null pointer Exception    java-forums.org

Hi... I am using XML file system. I am Retrieving XML elements using DOM parser and Storing elements as class Attributes. While executing the parsed file alone (fileScanner.java), i am getting the attribute values properly. But, when accessing fileScanner.java through .jar files, i am getting Null Pointer Exception for the same attribute value. How to rectify this and execute the same. ...

42. NullPointerException problem    java-forums.org

hello. i am trying to log on to the video library system that i just developed. when i type "Administrator" in the username text field and 0 in the password field and press OK i get a lot of NullPointerException problems (the appropriate pieces of code are shown below). i had to press End on the jGRASP console in order to ...

43. NullPointerException: I can't get rid of it.    java-forums.org

Guys/Gals, I am desperately trying to get rid of this nullpointerexception but for the life of me i can't figure out where it's coming from... It happens upon entry into the createShowGUI method. Java Code: import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; ...

44. java.lang.NullPointerException    java-forums.org

Hey, I've been having a problem with one of my programming assignments. I keep getting the message: Exception in thread "main" java.lang.NullPointerException at queueTask.TpQueue.front(TpQueue.java:29) at queueTask.TpQueue.main(TpQueue.java:53) on this code: Java Code: package queueTask; import simpleLists.*; public class TpQueue implements Queue { private SimpleList _contents; @Override public E deQueue() throws EmptyQueueException { // TODO Auto-generated method stub if (_contents.isEmpty() == true) throw ...

45. Problem with null pointer exception?    java-forums.org

Java Code: package javaapplication1; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.KeyEvent; import java.awt.event.KeyListener.*; import java.awt.event.*; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; public class CallDummy { static Dummy DI = new Dummy(); static Graphics g = DI.getGraphics(); public static void main (String args[]){ DI.Init(); DI.run(); } } class Dummy extends JPanel implements KeyListener,Runnable{ Image BackGround; Image Char; Dimension size; ...

46. NullPointerException in basic GUI    java-forums.org

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at ColorPanel1.paintComponent(ColorPanel1.java:22) at javax.swing.JComponent.paint(JComponent.java:1029) at javax.swing.JComponent.paintChildren(JComponent.java:862) at javax.swing.JComponent.paint(JComponent.java:1038) at javax.swing.JComponent.paintChildren(JComponent.java:862) at javax.swing.JComponent.paint(JComponent.java:1038) at javax.swing.JLayeredPane.paint(JLayeredPane.java:567) at javax.swing.JComponent.paintChildren(JComponent.java:862) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131) at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManag er.java:278) at javax.swing.RepaintManager.paint(RepaintManager.java:1224) at javax.swing.JComponent.paint(JComponent.java:1015) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java: 60) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97 ) at java.awt.Container.paint(Container.java:1780) at java.awt.Window.paint(Window.java:3375) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713) at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:6 93) at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System EventQueueUtilities.java:125) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre ad.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread. ...

47. java.lang.NullPointerException    java-forums.org

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AppPanel extends JPanel { private Die die1, die2, die3, die4, die5 = new Die(6); private Dice dice = new Dice(); private JLabel total, d1, d2, d3, d4, d5 = new JLabel("0"); private JButton rollAll, roll1, roll2, roll3, roll4, roll5 = new JButton("Roll"); public AppPanel() { dice.addDie(die1); dice.addDie(die2); dice.addDie(die3); dice.addDie(die4); dice.addDie(die5); //rollAll.addActionListener(new RollAllListener()); add(rollAll); ...

48. NullPointerException    java-forums.org

Hi, In my program i don't have any errors while compiling but i am getting this error while compiling: Here is the Error code: "Exception in thread "main" java.lang.NullPointerException at library.(library.java:205) at library.main(library.java:515) Press any key to continue..." The program code is below starting from the line number 205 as indicated in error. The below code is written under ActionListener: find.addActionListener(new ...

49. NullPointerException - createImage()    java-forums.org

import java.awt.*; import javax.swing.*; public class Panela extends JPanel implements Runnable{ int korak=0; int zakasnitev=50; boolean running=false; Image memImage; Graphics memGraphics; Thread nit; Panela(){ **memImage= createImage(500,500); ***memGraphics = memImage.getGraphics(); setVisible(true); start(); } public void run(){ while(running){ long cas=System.currentTimeMillis(); korak++; repaint(); cas=System.currentTimeMillis(); try{ if(cas