participate


New To Java Technology Archive - How can you find this bug???
<<   Back to Forum  |   Give us Feedback
This topic has 17 replies on 2 pages.    1 | 2 | Next »
ablivian23
Posts:92
Registered: 4/23/03
How can you find this bug???   
Jul 29, 2004 8:25 AM

 
I am getting the following exception, which does specify any lines in my code, so how can I track down the problem --- any ideas?

TIA,
ablivian23

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.plaf.basic.BasicScrollPaneUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
	at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
 
FranklinT
Posts:93
Registered: 3/6/01
Re: How can you find this bug???   
Jul 29, 2004 8:32 AM (reply 1 of 17)  (In reply to original post )

 
Here's a crazy thought. How about running your program in a debugger, or failing that dropping println statements in there to see what's going on?
 
legosa
Posts:1,183
Registered: 1/23/02
Re: How can you find this bug???   
Jul 29, 2004 8:34 AM (reply 2 of 17)  (In reply to original post )

 
Yickes. Did you recompile the JRE yourself? If not, what version of JRE are you using?
 
legosa
Posts:1,183
Registered: 1/23/02
Re: How can you find this bug???   
Jul 29, 2004 8:36 AM (reply 3 of 17)  (In reply to #1 )

 
Here's a crazy thought.

It is a bit crazy, isn't it? Given that the stacktrace doesn't contain a single application class and all.
 
omegaNetwork
Posts:281
Registered: 12/23/03
Re: How can you find this bug???   
Jul 29, 2004 8:37 AM (reply 4 of 17)  (In reply to #2 )

 
Are you by any chance trying to impelment a new L&F within your application? This sort of exceptions occur when you are using a L&F that was written with either a newer or older version of the JDK.

Otherwise, post some code
 
ablivian23
Posts:92
Registered: 4/23/03
Re: How can you find this bug???   
Jul 29, 2004 2:41 PM (reply 5 of 17)  (In reply to #4 )

 
Here's a crazy thought. How about running your
program in a debugger, or failing that dropping println
statements in there to see what's going on?

You should probably read my question again -- I don't think you understand the situation.

Are you by any chance trying to impelment a new L&F
within your application? This sort of exceptions occur
when you are using a L&F that was written with either
a newer or older version of the JDK.

Otherwise, post some code

I am not trying to use a new L&F. Ummm as for code there is a lot of swing component -- but I think that it may be in this code:

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Vector;
 
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;
 
public class GUIManager
	extends javax.swing.JFrame
	implements java.io.Serializable {
	public GUIManager() {
		super("GUI Manager");
 
		content = new Vector();
		names = new Vector();
		twice = false;
 
		screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
 
	}
	public void initComponents() {
		list = new JList(names);
		scrollPane = new JScrollPane();
 
		getContentPane().setLayout(
			new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
 
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
 
		scrollPane.setViewportView(list);
 
		getContentPane().add(scrollPane);
 
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(
				javax.swing.event.ListSelectionEvent evt) {
				int index = list.getMinSelectionIndex();
				setContent(index, true);
			}
		});
 
		pack();
	}
	public GUIManager(BorderContent[] bc) {
		super("GUI Manager");
 
		content = new Vector();
		names = new Vector();
		twice = false;
 
		screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
 
		for (int i = 0; i < bc.length; i++) {
			bc[i].createContent();
			content.add(bc[i]);
			names.add(bc[i].getTitle());
		}
 
		list = new JList(names);
		scrollPane = new JScrollPane();
		label = new JLabel("Select View");
 
		getContentPane().setLayout(
			new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
 
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
 
		scrollPane.setViewportView(list);
 
		getContentPane().add(label);
		getContentPane().add(scrollPane);
 
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(
				javax.swing.event.ListSelectionEvent evt) {
				int index = list.getMinSelectionIndex();
				setContent(index, true);
			}
		});
 
		pack();
 
		setVisible(true);
 
		setContent(0, false);
 
	}
	private void setContent(int contentIndex, boolean dispose) {
		if (twice) {
			twice = !twice;
			return;
		}
		if (dispose) {
			gui.dispose();
		}
		gui = new TemplateGUI((BorderContent) content.get(contentIndex));
		gui.setLocation(new java.awt.Point(getX() + getWidth(), getY()));
		gui.setSize(
			new java.awt.Dimension(
				(int) (screenSize.getWidth() - getWidth() - MARGIN),
				(int) screenSize.getHeight() - MARGIN));
		gui.setVisible(true);
		twice = !twice;
	}
	public void add(BorderContent bc) {
		//Dimension size = getSize();
		bc.createContent();
		content.add(bc);
		names.add(bc.getTitle());
	}
	public void add(BorderContent bc, String customTitle) {
		//Dimension size = getSize();
		bc.createContent();
		content.add(bc);
		names.add(customTitle);
 
	}
	public void add(BorderContent bc, String customTitle, boolean serialize) {
		if (serialize) {
			BorderContent serial_bc = null;
			try {
				File file =
					File.createTempFile(customTitle.replace(' ', '_'), ".tmp");
 
				FileOutputStream fos = new FileOutputStream(file);
				ObjectOutputStream oos = new ObjectOutputStream(fos);
				oos.writeObject(bc);
 
				//Read In
				FileInputStream fis = new FileInputStream(file);
				ObjectInputStream ois = new ObjectInputStream(fis);
				serial_bc = (BorderContent) ois.readObject();
 
				ois.close();
				fis.close();
				oos.close();
				fos.close();
 
			} catch (Exception e) {
 
			}
 
			add(serial_bc, customTitle);
		} else {
			add(bc, customTitle);
		}
	}
	public void initGUI() {
		initComponents();
		setVisible(true);
		setContent(0, false);
 
	}
	/**
	 *@param bc the BorderContent that the user would like displayed first
	 */
	public void initGUI(BorderContent bc) {
		initComponents();
		setVisible(true);
		int index = content.indexOf(bc);
		setContent((index == -1 ? 0 : index), false);
	}
 
	public class TemplateGUI
		extends javax.swing.JFrame
		implements java.io.Serializable {
 
		public TemplateGUI(BorderContent bc) {
			//Initialize all objects
			super();
 
			Component center = bc.getCenterContent();
			Component east = bc.getEastContent();
			Component south = bc.getSouthContent();
			Dimension size = bc.getSize();
 
			setTitle(bc.getTitle());
 
			if (center != null) {
				getContentPane().add(center, BorderLayout.CENTER);
			}
			if (east != null) {
				getContentPane().add(east, BorderLayout.EAST);
			}
			if (south != null) {
				getContentPane().add(south, BorderLayout.SOUTH);
			}
 
			pack();
			p("bc = " + bc);
			//if (size != null) {
			//	setSize(size);
			//}
		}
	}
	public static void p(String s) {
		System.out.println(s);
	}
 
	//Content for the manager to manage
	private TemplateGUI gui;
	private Vector content;
	private Dimension screenSize;
 
	//Components to display list
	private JScrollPane scrollPane;
	private JList list;
	private JLabel label;
	private Vector names;
	private boolean twice;
	private final int MARGIN = 100;
	//Pixel border between the displayed table and the edge of the screen
 
}
 
ablivian23
Posts:92
Registered: 4/23/03
Re: How can you find this bug???   
Jul 29, 2004 2:44 PM (reply 6 of 17)  (In reply to #5 )

 
legosa --

I have compiled the source with both jdks 1.5.0 and 1.4.2 and it gets the same exceptions with jre versions of 1.3.1, 1.4.2 and 1.5.0.

Thanks,
ablivian23
 
bbritta
Posts:8,810
Registered: 10/4/00
Re: How can you find this bug???   
Jul 29, 2004 3:26 PM (reply 7 of 17)  (In reply to #6 )

 
I'm not sure whether I should be impressed or just break down sobbing. You might try mentioning what you are doing when the error occurs. It looks like it might be happening when you open one of these TemplateGUI thingies. Or maybe the second one???

From a quick look at your code, the only thing that jumps to mind is that a component can only have one parent. If you have a component in one container and then add it to another, it is removed from the first container.
 
legosa
Posts:1,183
Registered: 1/23/02
Re: How can you find this bug???   
Jul 29, 2004 3:29 PM (reply 8 of 17)  (In reply to #6 )

 
I have compiled the source with both jdks 1.5.0 and 1.4.2 and it gets the same exceptions with jre versions of 1.3.1, 1.4.2 and 1.5.0.

OK, but you did you (intentionally or accidentally) recompile the JRE itself? "Unknown Source" in a stack trace means that the class was compiled without debugging information (javac -g:none). It's very unusual to see that with java.* classes, since Sun compiles the standard JRE distributions with full debugging info.
 
legosa
Posts:1,183
Registered: 1/23/02
Re: How can you find this bug???   
Jul 29, 2004 3:45 PM (reply 9 of 17)  (In reply to #8 )

 
With regards to your immediate problem - it looks like you're creating a BasicScrollPaneUI but forgetting to call installUI() on it someplace.
 
jverd
Posts:51,793
Registered: 3/30/99
Re: How can you find this bug???   
Jul 29, 2004 3:52 PM (reply 10 of 17)  (In reply to #5 )

 
Here's a crazy thought. How about running your
program in a debugger, or failing that dropping
println
statements in there to see what's going on?

You should probably read my question again -- I don't
think you understand the situation.

The suggestion is applicable to your situation. It's just that a) you don't really know where to dbug or println and b) even if you find out which line of your code is triggering this, you may not be able to easily figure out what to do about it.

Presumably the reason you don't see any of your code in the stack trace is because it's a different thread.

You can put print statements in or debug and see how far your code is getting before this happens. Since it's a separate thread, you may get different results each time you run it, but hopefully if you do it enough, you'll see a small handful of statements show up the most. A few calls to sleep() could help narrow it down after that.

When you say you tried various JREs, are you sure? Is it possible there's an older JRE that appears earlier in your PATH?
 
FranklinT
Posts:93
Registered: 3/6/01
Re: How can you find this bug???   
Jul 30, 2004 8:38 AM (reply 11 of 17)  (In reply to #5 )

 
I understand your problem - you've got a bug somewhere, and the debugging info you're being handed doesn't give you a whole lot to go by.

So run the code through a debugger, or if you don't have one start dropping println statements in there. You need to figure out what line of code triggers this error so you can work backwards from there to find the ultimate source of the problem.
 
PeteKirkham
Posts:441
Registered: 2/25/04
Re: How can you find this bug???   
Jul 30, 2004 8:49 AM (reply 12 of 17)  (In reply to original post )

 
(Assuming Sun JSDK 1.4)

BasicScrollPaneUI.paint is
    public void paint(Graphics g, JComponent c) {
	Border vpBorder = scrollpane.getViewportBorder();
	if (vpBorder != null) {
	    Rectangle r = scrollpane.getViewportBorderBounds();
	    vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
	}
    }

There is a check on vpBorder before it's dereferenced, so it can't be causing the exception.

Since scrollpane.getViewportBorderBounds() creates a new rectangle and returns it, it cannot be null.

Therefore the only reference that can be null is scrollpane.

The scrollpane field is set in the installUI() and the uninstallUI() methods. The normal JComponent implementation maintains the inverse relation, so that a component won't call the ui paint method of any ui that isn't installed.

Are you doing anything with these two methods that would break the association?

Pete
 
bellyripper
Posts:1,995
Registered: 2000.12.10.
Re: How can you find this bug???   
Jul 30, 2004 8:55 AM (reply 13 of 17)  (In reply to #12 )

 
I have a feeing you access components from non-gui thread after they have been realized.
pack();
setVisible(true);
setContent(0, false);


Solution will be to call setContent before packing making the frame visible

HTH
Mike
 
ablivian23
Posts:92
Registered: 4/23/03
Re: How can you find this bug???   
Aug 2, 2004 12:50 PM (reply 14 of 17)  (In reply to #9 )

 
With regards to your immediate problem - it looks like
you're creating a BasicScrollPaneUI but forgetting to
call installUI() on it someplace.

I am not creating a BasicScrollPaneUI anywhere in my code.
 
This topic has 17 replies on 2 pages.    1 | 2 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 63
  • Guests : 118

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums