• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 998
  • Last Modified:

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

0
rohitdivas
Asked:
rohitdivas
1 Solution
 
zzynxSoftware engineerCommented:
>> 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++)
0
 
zzynxSoftware engineerCommented:
>>java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
indicates that getColumnModel() has no columns yet
0
 
rohitdivasAuthor Commented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TimYatesCommented:
> 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...
0
 
zzynxSoftware engineerCommented:
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
0
 
zzynxSoftware engineerCommented:
>> 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
0
 
CEHJCommented:
Can you please post your main method
0
 
rohitdivasAuthor Commented:
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
0
 
zzynxSoftware engineerCommented:
>> The code is working fine after changing the for loop as suggested. Thanks zzynx
Good!

>> One thing still left is =>why the same application runs fine on jdk 1.4 and not on jdk 1.5 ?
As previously said: changes in the underlying code.
I feel the for loop as it is now to be much safer. Maybe you just had luck in 1.4
0
 
rohitdivasAuthor Commented:
u deserve these  points zzynx.
thanks,
rohit
0
 
zzynxSoftware engineerCommented:
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
0
 
zzynxSoftware engineerCommented:
>> u deserve these  points zzynx.
But apparently no A-grade?
0
 
rohitdivasAuthor Commented:
:) I didnot got the reason for the incompaitbility. (at same time got solution to urgent problem)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now