JGoView, getViewListeners()


#1

Hello,
I have some exceptions each time I want use the method getViewListeners() of a JGoView object.
I add 2 JGoViewListener, then I want remove them, so I use the method getViewListeners() to get the list of the JGoviewListeners, but I get a ClassCastException.
If I don’t add any JGoViewListener, then I get a NullPointerException.
I checked the source code, I’m sure it’s a bug.
Alexandre Pique
apique@isoft.fr
ISoft


#2

Yes, you’re quite right!
Please change getViewListeners() as follows.
Before:
public JGoViewListener[] getViewListeners()
{
return (JGoViewListener[])(myViewListeners.toArray());
}
After:
public JGoViewListener[] getViewListeners()
{
if (myViewListeners == null)
return null;
Object[] objListeners = myViewListeners.toArray();
JGoViewListener[] jgoviewListeners = new JGoViewListener[objListeners.length];
for (int i = 0; i < objListeners.length; i++) {
jgoviewListeners = (JGoViewListener)objListeners;
}
return jgoviewListeners;
}


#3

Sorry, there’s a typo in my last reply. The “After” code should be as follows:
public JGoViewListener[] getViewListeners()
{
if (myViewListeners == null)
return null;
Object[] objListeners = myViewListeners.toArray();
JGoViewListener[] jgoviewListeners = new JGoViewListener[objListeners.length];
for (int i = 0; i < objListeners.length; i++) {
jgoviewListeners[ i ] = (JGoViewListener)objListeners[ i ];
}
return jgoviewListeners;
}