• 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

ArrayList of ArrayList<String>

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am doing some integration stuff and adding some xml nodes values in a list for a xml file. Once I am done with one file I have to add that list to another list.
There are multiple xml files add I want to make a list of list.
I created something like this but it didn't work-
ArrayList<ArrayList<String>> arr=new ArrayList<ArrayList<String>>();

Can you guys get me some ideas on this...
Note- I dont want to create a Array of ArrayList as I dont know size. I am dealing dynamacally and there may be addition to the xml file dynamically.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That ought to work fine, so I suspect that the problem is really somewhere else.

Though I'd prefer to use
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless. What does it not do, and what should it do?
 
Umesh Vajpai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What basically I am trying to do is that get all the properties/nodes from the object xml file and write them in the salesforce database.
I dont know why I am getting Null Pointer/Array Index out of bound Exception when I use ArrayList of ArrayList..
If I use Arraylist of String with single record that I stored by reading xml, then I dont see any issue.However, for Arraylist of arraylist its throwing exception.
Here you can see the Sample code-




This method works fine with hardcoded values and in the same way I am trying to do with more than one list .


I am getting a list by reading a xml file and adding them in another list in this way..
Sample code-
Suppose I added 10 elements in it..I would now add this in my another list as I am done with one xml file and will read another.

I will pass this collection to createObjects(....) method with all required arguments but it throws null pointer exception..
I have put comments on the line where I got exception.

Please do help me to understand what wrong I have done and what needs to correct to make it work...

[Edit - added code tags - MB]

 
Umesh Vajpai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would be great help if someone can provide me sample code to write arrayList of ArrayList to any database.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Umesh Vajpai wrote:Would be great help if someone can provide me sample code to write arrayList of ArrayList to any database.


Well, first of all, this site is NotACodeMill. Second, you could do yourself a lot of favours by reading the UseCodeTags page.

The reason for both exceptions is very simple:
1. IndexOutOfBoundsException is produced when you are trying to access an element that doesn't exist in your ArrayList; and I can certainly see why that might be - the "record" that you're returning almost certainly has fewer elements than your 'ObjectApiNames' array. What I suggest you do is to print out what you're getting from your 'get()' statement.
2. NullPointerException is produced because something is null. Since I have no idea what binding.create() does, it would be useless to speculate why, but you could try printing out the contents of 's' immediately before you call it. Also, reading the API documentation for that method might tell you if/when it throws an NPE.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Umesh Vajpai wrote:Suppose I added 10 elements in it...


But that's precisely what you can't do. You must add at least 12 elements to it, because that's the number of labels you have (at least I assume that's what's in ObjectApiNames).

I would now add this in my another list as I am done with one xml file and will read another.


As Matthew pointed out, you're much better off using List<List<String>> - in your method parameter as well as your field definition. Have a look at his post again.

Winston
 
Umesh Vajpai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for your inputs..I will try out the way your guys suggested.
I appreciate your help..!!!
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic