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

rohitdivasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.