Skip to main content

crazy error

12 replies [Last post]
azurianarcher
Offline
Joined: 2006-02-17
Points: 0

got yet another problem, im trying to write an object out to disk using the following code:

<br />
	public void export()<br />
	{<br />
		JFileChooser fc = new JFileChooser();<br />
		fc.setFileFilter(new CabinetFileFilter());</p>
<p>		if(fc.showDialog(parent,"Export") == JFileChooser.CANCEL_OPTION)<br />
			return;<br />
		if(fc.getSelectedFile() == null)<br />
			return;</p>
<p>		if(Various.getFileExtension(fc.getSelectedFile()) == null||!(Various.getFileExtension(fc.getSelectedFile()).equals(".cabinet")))<br />
		{<br />
			File temp = new File(fc.getSelectedFile().getName() + ".cabinet");<br />
			fc.setSelectedFile(temp);<br />
		}</p>
<p>		try<br />
		{<br />
			fc.getSelectedFile().createNewFile();<br />
		}catch(IOException ie)<br />
		{<br />
			JOptionPane.showMessageDialog(null,"Unable to create new file");<br />
		}	</p>
<p>		ObjectOutputStream out = null;</p>
<p>		try<br />
		{<br />
			out = new ObjectOutputStream(new FileOutputStream(fc.getSelectedFile()));<br />
		}catch(Exception e)<br />
		{<br />
			JOptionPane.showMessageDialog(null,"Unable to initialize writer");<br />
			return;<br />
		}</p>
<p>		try<br />
		{<br />
			out.writeObject(selected);<br />
		}catch(Exception e)<br />
		{<br />
			JOptionPane.showMessageDialog(null,"Unable to write to file");<br />
			return;<br />
		}<br />
		repaint();<br />
	}<br />

When i run it it throws an exception that winds so far down im not even guna post it, but i am guna post the begining, i thnk thats the only part that really matters:

<br />
Exception occurred during event dispatching:<br />
java.lang.NullPointerException<br />
        at com.sun.java.swing.plaf.gtk.SynthButtonUI.getPreferredSize(SynthButto<br />
nUI.java:345)<br />
        at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)<br />
        at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:892)<br />
        at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:806)<br />
        at java.awt.GridBagLayout.preferredLayoutSize(GridBagLayout.java:630)<br />
        at java.awt.Container.preferredSize(Container.java:1178)<br />
        at java.awt.Container.getPreferredSize(Container.java:1162)<br />
        at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)<br />
        at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:892)<br />
        at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:806)<br />
        at java.awt.GridBagLayout.preferredLayoutSize(GridBagLayout.java:630)<br />
        at java.awt.Container.preferredSize(Container.java:1178)<br />
        at java.awt.Container.getPreferredSize(Container.java:1162)<br />
        at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)<br />
        at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:76<br />
9)<br />

and it keeps going and going(215 lines in total)

iv been trying to figre this out for a while an cant, can anyone help me?

~Amx

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shan-man
Offline
Joined: 2006-02-17
Points: 0

Hi,

Amx wrote:
> If you want to i can put the origional in some kind
> of archive(jar,zip,w/e) and send it to someone, but
> youd have to read through my messy code

As I mentioned earlier, I'd love to see a "minimal" test case. It would be much more useful than the source for your entire application. The best approach for creating a minimal test case is to start with your big application and methodically remove things that aren't relevant to the problem.

For example: Say you have an application with a JFrame, containing a menu, a tool bar, a panel with a bunch of components, and a lot of business logic. The bug happens when you try to write the panel to file.

So, strip out the menu, the toolbar, and the business logic and you've got a smaller test case. Does it still reproduce the error?

If so, look at the panel you're writing to file. The exception is occuring when some button is serialized. Perhaps the JTable, the JTree, and a whole bunch of other stuff on the panel isn't relevant either. So remove it, recompile and see if the problem is still there...etc...etc...until you feel you have a minimal test case.

This is an excellent approach any time you want to ask about a problem you're seeing, or when submitting bug reports. Another benefit of this technique is that in many cases, you'll find the problem yourself during this process.

With respect to Scott's suggestion of submitting a bug report, that is a good suggestion in this case, since this is likely a bug in Swing. However, if you'd like confirmation or a work around in the near future, I'd recommend continuing the discussion here too.

Thanks, and I hope this all helps!
Shannon

azurianarcher
Offline
Joined: 2006-02-17
Points: 0

ok, i stripped down the origional to debug it, its still huge an now it throws a different exception

~Amx

shan-man
Offline
Joined: 2006-02-17
Points: 0

Amx,

Amx wrote:
> ok, i stripped down the origional to debug it, its
> still huge an now it throws a different exception

Sorry to hear that. Looks like you're going to have to try again. Remember, this is an incremental process. Pull out a section of code at a time. If it changes the exception that you're seeing, put it back and try something else. If you have an understanding of the code base that you're working on, it should be pretty obvious what's related and what's not.

Shannon

azurianarcher
Offline
Joined: 2006-02-17
Points: 0

im guna do that, also, i found something veryu weird out yesterday that cant be seen from the portion of the stack trace i origionally posted, the problem seems to be occurring in the messaage dialog i showed using the JOptionPane method, that part of the stack trace is:
[code]
...
at java.awt.Dialog$1.run(Dialog.java:540)
at java.awt.Dialog.show(Dialog.java:561)
-->at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:840)
-->at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:642)
-->at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:613)
-->at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:584)
at ButtonsPanel.export(FileCabinet.java:617)
at FileCabinet.actionPerformed(FileCabinet.java:343)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
86)
...
[/code]

~Amx

shan-man
Offline
Joined: 2006-02-17
Points: 0

Amx,

Unfortunately, little pieces from the middle of stack traces don't tell us much of anything. It sure doesn't show me whether or not JOptionPane is related to your bug. Please continue trying to come up with a test case. Then we can see the exception in its entirety and let you know what's going on.

Regards,
Shannon

azurianarcher
Offline
Joined: 2006-02-17
Points: 0

gah, no matter what i do the error changes

~Amx

azurianarcher
Offline
Joined: 2006-02-17
Points: 0

no im not running it in a different thread that i know of. 'selected' is a JPanel. I tried writing a program the implemented the exact same export() method, and it worked.

~Amx

shan-man
Offline
Joined: 2006-02-17
Points: 0

Hi Amx,

Amx wrote:
> no im not running it in a different thread that i
> know of. 'selected' is a JPanel. I tried writing a
> program the implemented the exact same export()
> method, and it worked.

Perhaps you didn't build the component hierarchy the same way. For example, if the object you're trying to write to file is a JPanel, maybe you forgot to add the buttons to it that you added in your other application.

When an object is serialized, any objects that it references are also serialized. So writing a JPanel to file will also write any components that it contains.

Regards,
Shannon

azurianarcher
Offline
Joined: 2006-02-17
Points: 0

ya thats probobly got a lot to do with it, also it seems to be look and feel related, b/c it works with the metal look and feel, throws a different exception with windows look and feel, and throws that exception with gtk look and feel

If you want to i can put the origional in some kind of archive(jar,zip,w/e) and send it to someone, but youd have to read through my messy code

~Amx

Scott Violet

On Tue, Dec 02, 2003 at 03:37:26PM -0500, swing-feedback@javadesktop.org wrote:
> ya thats probobly got a lot to do with it, also it seems to be look and feel related, b/c it works with the metal look and feel, throws a different exception with windows look and feel, and throws that exception with gtk look and feel
>
> If you want to i can put the origional in some kind of archive(jar,zip,w/e) and send it to someone, but youd have to read trhough my messy code

Amx,

The easiest way to handle this is to file a bug on the JDC, You can
attach the source there and we'll investigate.
Thanks,

-Scott

shan-man
Offline
Joined: 2006-02-17
Points: 0

Hi,

What is this "selected" object that you're trying to write out to the file? If possible, posting a small runnable test case would help so much more. Except for the "writeObject(selected)" call, the code you've posted, unfortunately, has nothing to do with the problem. Posting a runnable example would allow us to see the relevant lines and give us an opportunity to debug it.

Thanks!
Shannon

Scott Violet

On Sun, Nov 30, 2003 at 01:17:31PM -0500, swing-feedback@javadesktop.org wrote:
> got yet another problem, im trying to write an object out to disk
> using the following code:

> and it keeps going and going(215 lines in total)
>
> iv been trying to figre this out for a while an cant, can anyone help me?

What is the line of code in your application that triggered this? Are
you doing this on a thread other than the event dispatching thread?

-Scott