Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
List to String error got running on Eclipse(Java perspective)
Leonidas Savvides
Ranch Hand
Posts: 403
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
running on Eclipse(
Java
perspective) got:
Exception in
thread
"main" java.lang.ArrayIndexOutOfBoundsException: 0
at ListToString.main(ListToString.java:32)
public static void main(String[] args) { List<String[]> list = new ArrayList<String[]>(); String[] stg1={}; List<String[]> names2 ; list.add( new String[]{ "fdgf", "gfcg", "gdg", "dgdg" } ); list.add( new String[]{ "fdgf1", "gfcg1", "gdg1", "dgdg1" } ); list.add( new String[]{ "fdgf2", "gfcg2", "gdg2", "dgdg2" } ); list.add( new String[]{ "fdgf3", "gfcg3", "gdg3", "dgdg3" } ); list.add( new String[]{ "fdgf4", "gfcg4", "gdg4", "dgdg4" } ); names2 = list; int x=0; String stg; for (String[] name : names2) { stg = name[1]+" - "+name[2]+ " - "+name[3]+" - "+name[3]; stg1[x]=stg; // LINE:32 System.out.println(stg); x++; } }
Joanne Neal
Rancher
Posts: 3742
16
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
On line 5 you declare stg1 as a zero length array.
On line 22 you try and put something into the first element of that array.
Joanne
Leonidas Savvides
Ranch Hand
Posts: 403
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you MEAN USE
String
[list.size()] stg1;
Leonidas Savvides
Ranch Hand
Posts: 403
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
String[] stg1=new String[list.size()];
success, thks
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
getting the value of string array out of object array
how to link parent[first list.xml] to second child[second list_item.xml]
sublist of arraylist???
custom taglib problem
add(index,object) and reverseOrder()
More...