on 01-04-2010 3:36 PM
Hi,
I am getting java.lang.NullPointerException when creating an empty record for Record[] variable. Can you advice what is the issue here. I am trying to assign multiple records in Record array, so that i can use CreateRecordsCommand.
//Create Multiple Records
Record[] emptyRecordsProduct = null;
emptyRecordsProduct[0] = RecordFactory.createEmptyRecord(tableId);
Your help is really appreciated.
Thanks
Vijay
Hi Vijay,
You have not fully initialized the array yet. You are trying to put the new Record object into a spot in the array that doesn't exist, hence the null pointer.
Instead of this line:
Record[] emptyRecordsProduct = null;
Use this:
Record[] emptyRecordsProduct = new Record[1];
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
I would look at temporarily keeping the Record objects in some other collection type other than an array. There are several type of Java objects that inherit from Collection that would work. ArrayList is an example. Using this makes adding new Records to the ArrayList easy. When an MDM command needs a Record array you can convert your ArrayList of Record objects into a Record array. Here is an example of creating an ArrayList, adding a record (assuming you already have the Record object), and converting the ArrayList to a Record array:
ArrayList arrList = new ArrayList();
arrList.add(record)
Record[] recArray = new Record[arrList.size()];
recArray = (Record[])arrList.toArray(recArray);
Here is a link that goes into some of the Java Collections. http://java.sun.com/docs/books/tutorial/collections/index.html
Hope this helps,
Greg
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.