Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » "Instantiation Exception"
"Instantiation Exception" [message #65594] Thu, 07 October 2004 19:21 Go to next message
Eclipse UserFriend
Originally posted by: cdouglas.nospam.oz.net

I laid out a nice screen set with VE, and now I'm trying to add some
"controller" behavior.

I locally subclassed a JPanel to add ActionListener and FocusListener
interfaces. I put some buttons inside this panel, and now VE won't draw it
and complains of a "java.lang.InstantiationException (dialogs.PatientDialog
$GenderPanel)" from the Java Beans view. Nothing in the PDE log seems
relevant (although there are some errors on other fields). It compiles and
runs correctly.

Here is my internal class:
public class GenderPanel extends JPanel implements ActionListener,
FocusListener {
public void actionPerformed(ActionEvent e) {
setGender();
}
public void focusGained(FocusEvent e) {
// ignore
}
public void focusLost(FocusEvent e) {
setGender();
}
private void setGender() {
if (maleButton.isSelected()) {
patient.setGender(1);
}
else if (femaleButton.isSelected()) {
patient.setGender(2);
}
}
}

And here is the VE generated code for the panel:

private PatientDialog.GenderPanel getNewGenderPanel() {
if (newGenderPanel == null) {
newGenderPanel = new PatientDialog.GenderPanel();
newGenderPanel.setBounds(31, 35, 161, 55);
newGenderPanel.add(getMaleButton(), null);
newGenderPanel.add(getFemaleButton(), null);
}
return newGenderPanel;
}

I'm using Eclipse: 200409161125
With VE/EMF/GEF from the update site

An I going about this the wrong way?

Chas Douglass
Re: "Instantiation Exception" [message #65615 is a reply to message #65594] Thu, 07 October 2004 20:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

We don't support non-static inner classes. The problem with non-static
inner classes is that to instantiate them we need to have an instance of
the outer class. But since that is class being developed, there is no
outer class instance to get an instance of. So you get an
InstantiationError.

If it was static inner class we could do it. But the better way is not
use an inner class. Since you only need one instance of this class, and
you aren't using it anywhere else (or more than once), then just drop a
JPanel and and an Action and Focus event to it using the Add Events...
from the popup menu on the JPanel.

--
Thanks,
Rich Kulp
Re: "Instantiation Exception" [message #65634 is a reply to message #65615] Thu, 07 October 2004 20:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdouglas.nospam.oz.net

Rich Kulp <richkulp@us.NO_SPAM.ibm.com> wrote in
news:ck47b3$51f$1@eclipse.org:

> We don't support non-static inner classes. The problem with non-static
> inner classes is that to instantiate them we need to have an instance
> of the outer class. But since that is class being developed, there is
> no outer class instance to get an instance of. So you get an
> InstantiationError.
>
> If it was static inner class we could do it. But the better way is not
> use an inner class. Since you only need one instance of this class,
> and you aren't using it anywhere else (or more than once), then just
> drop a JPanel and and an Action and Focus event to it using the Add
> Events... from the popup menu on the JPanel.
>

Thanks, as it turns out, the panel doesn't get any interesting events
anyway.

I'm now putting the controller code into the "getXXX()" routine
generated by VE. When I add some initialization (like:

if (patient.getGender() == 1) {
button.setSelected(true);
}

And then add the "action performed" event with VE, VE decides to add the
code right after the opening brace of that code -- which in this case
means if my patient isn't male, there will be no action listener.

Of course I fixed it manually, but how does VE decide where to put code?
Is there a more appropriate place for me to put my initialization?

Thanks for your help.

Chas Douglass
Re: "Instantiation Exception" [message #65655 is a reply to message #65634] Thu, 07 October 2004 20:57 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

It shouldn't do that. It should of put it either before or after the if
statement and its then/else expressions.

Please open a Bugzilla against VE product, and JavaCore component.

Add into the comment for the bug the actual final code that the VE
generates, show us the whole getButton() method please.



--
Thanks,
Rich Kulp
Re: "Instantiation Exception" [message #601059 is a reply to message #65594] Thu, 07 October 2004 20:06 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

We don't support non-static inner classes. The problem with non-static
inner classes is that to instantiate them we need to have an instance of
the outer class. But since that is class being developed, there is no
outer class instance to get an instance of. So you get an
InstantiationError.

If it was static inner class we could do it. But the better way is not
use an inner class. Since you only need one instance of this class, and
you aren't using it anywhere else (or more than once), then just drop a
JPanel and and an Action and Focus event to it using the Add Events...
from the popup menu on the JPanel.

--
Thanks,
Rich Kulp
Re: "Instantiation Exception" [message #601063 is a reply to message #65615] Thu, 07 October 2004 20:28 Go to previous message
Chas Douglass is currently offline Chas DouglassFriend
Messages: 26
Registered: July 2009
Junior Member
Rich Kulp <richkulp@us.NO_SPAM.ibm.com> wrote in
news:ck47b3$51f$1@eclipse.org:

> We don't support non-static inner classes. The problem with non-static
> inner classes is that to instantiate them we need to have an instance
> of the outer class. But since that is class being developed, there is
> no outer class instance to get an instance of. So you get an
> InstantiationError.
>
> If it was static inner class we could do it. But the better way is not
> use an inner class. Since you only need one instance of this class,
> and you aren't using it anywhere else (or more than once), then just
> drop a JPanel and and an Action and Focus event to it using the Add
> Events... from the popup menu on the JPanel.
>

Thanks, as it turns out, the panel doesn't get any interesting events
anyway.

I'm now putting the controller code into the "getXXX()" routine
generated by VE. When I add some initialization (like:

if (patient.getGender() == 1) {
button.setSelected(true);
}

And then add the "action performed" event with VE, VE decides to add the
code right after the opening brace of that code -- which in this case
means if my patient isn't male, there will be no action listener.

Of course I fixed it manually, but how does VE decide where to put code?
Is there a more appropriate place for me to put my initialization?

Thanks for your help.

Chas Douglass
Re: "Instantiation Exception" [message #601066 is a reply to message #65634] Thu, 07 October 2004 20:57 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

It shouldn't do that. It should of put it either before or after the if
statement and its then/else expressions.

Please open a Bugzilla against VE product, and JavaCore component.

Add into the comment for the bug the actual final code that the VE
generates, show us the whole getButton() method please.



--
Thanks,
Rich Kulp
Previous Topic:"Instantiation Exception"
Next Topic:Pattern Style suggestion and GridBagConstraint question
Goto Forum:
  


Current Time: Sat Dec 21 14:46:39 GMT 2024

Powered by FUDForum. Page generated in 0.03811 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top