Link to home
Start Free TrialLog in
Avatar of wsyy
wsyy

asked on

java String array

Hi,

I have the following code:

Outlink[] otherOutLinks;
otherOutLinks = new Outlink[0];
otherOutLinks[0]=new Outlink(link, "Next");

Why does the third line cause an exception?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

How can I fix it?

Thanks
SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America 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
This could  work:

Outlink[] otherOutLinks;
otherOutLinks = new Outlink[1];
otherOutLinks[0]=new Outlink(link, "Next");

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia 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