Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList of ArrayList<String>

 
Umesh Vajpai
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless. What does it not do, and what should it do?
 
Umesh Vajpai
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would be great help if someone can provide me sample code to write arrayList of ArrayList to any database.
 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for your inputs..I will try out the way your guys suggested.
I appreciate your help..!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic