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.
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..
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]
Joined: Mar 14, 2010
Would be great help if someone can provide me sample code to write arrayList of ArrayList to any database.
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.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here