Link to home
Start Free TrialLog in
Avatar of rohitdivas
rohitdivas

asked on

Exception java.lang.ArrayIndexOutOfBoundsException: 0 >= 0

Hi,
Platform : Windows XP
I have an application that runs perfectly well on jdk1.4 but throws exception when used jdk 1.5. Following is the code at which the exception is thrown:
(so this problem is specific in JDK 1.5 and app works fine in JDK 1.4)
/*----------------
class CTModel
extends AbstractTableModel {
public int getRC() {
for (int k = 0; k < getColumnCount(); k++) {
getColumnModel().getColumn(k).setMaxWidth(8); ///////////////////exception thrown...
}
}
}
----------------*/
The exception is:::
///////////////
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:432)
at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:280)
at com.rainbow.superpro.GUI.ApiExplorer.CAPITable$CAPITableModel.getRowCount(CAPITable.java:116)
at javax.swing.JTable.checkLeadAnchor(JTable.java:2949)
at javax.swing.JTable.tableChanged(JTable.java:2993)
at javax.swing.JTable.setModel(JTable.java:2827)
at com.ra.sro.GUI.AExplorer.CAPITable.<init>(CAPITable.java:35)
at com.ra.sro.GUI.AExplorer.CAPIExplorer.<init>(CAExplorer.java:246)
at st.CSFrame.jbInit(CSPFrame.java:121)
at st.CFrame.<init>(CSFrame.java:93)
at st.Sro.main(SPro.java:104)
//////////////

HOW TO RESOLVE THIS EXCEPTION ??? Has any body encountered similiar problem ? Any ideas...
 

Please suggest.

Thanks ,
Rohit

Avatar of zzynx
zzynx
Flag of Belgium image

>> Has any body encountered similiar problem ?
Yes.

I think the columns are not yet added when you call this.

Try:
for (int k = 0; k < getColumnModel().getColumnCount(); k++)
>>java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
indicates that getColumnModel() has no columns yet
Avatar of rohitdivas
rohitdivas

ASKER

HI,
Thanks for quick response.

I commented the for loop and compiled following::::::

getColumnModel().getColumn(0).setMaxWidth(8);

Still the exceptions remains the same...Any ideas, b/w what are the various reason that the exception is coming only for JDK 1.5 and NOT on JDK 1.4

rohit
> I commented the for loop and compiled following::::::
> getColumnModel().getColumn(0).setMaxWidth(8);

As zzynx said, it looks like no columns have been added to the column model at the time you are calling this method...

> Any ideas, b/w what are the various reason that the exception is coming only for JDK 1.5 and NOT on JDK 1.4

I guess the underlying code has changed at what time the columns are added to the model...

Can you post some more of your code?

zzynx's solution of doing:

> for (int k = 0; k < getColumnModel().getColumnCount(); k++)

will stop the exception, but as there will be 0 columns, setMaxWidth will not be called at that time...
Please adapt the for loop as I told:
>> for (int k = 0; k < getColumnModel().getColumnCount(); k++)        // Note that I added getColumnModel(). before the getColumnCount() !!!

>>Still the exceptions remains the same
Of course. As I told: getColumnModel() has no columns yet,
so trying to get the first via getColumnModel().getColumn(0) leads to that error.

Don't know why this happens in 1.5 and not in 1.4
>> zzynx's solution
>> will stop the exception, but as there will be 0 columns, setMaxWidth will not be called at that time...
That's true.
You should be sure that getRC() is called *after* adding the columns
Can you please post your main method
I cannot paste the code since it's too large,

we have overridden all the above mentioned methods. The code is working fine after changing the for loop as suggested. Thanks zzynx.

One thing still left is =>why the same application runs fine on jdk 1.4 and not on jdk 1.5 ?

Thanks,
rohit
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
u deserve these  points zzynx.
thanks,
rohit
Thank you :°)

P.S.: For the people reading this afterwards, it would have been better to mark the comment that really helped you as accepted answer
>> u deserve these  points zzynx.
But apparently no A-grade?
:) I didnot got the reason for the incompaitbility. (at same time got solution to urgent problem)