cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.NullPointerException at CreateEmptyRecord(tableId)

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

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];

Former Member
0 Kudos

Greg,

Thanks for your reply.

I am reading data from an Excel file for BULK UPLOAD functionality. In the excel sheet, some are to Create and some are to Modify.

When i use new Record[1], how can i increase the array during runtime? Please advice.

Thanks for your help.

Thanks

Vijay

Greg_Austin
Active Participant
0 Kudos

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

Former Member
0 Kudos

Thanks Greg, problem solved with your solution. Awarded 10 points, thanks a lot for your help.

nitin_mahajan2
Contributor
0 Kudos

... ignore.

Edited by: Nitin Mahajan on Jan 6, 2010 5:36 PM

Answers (0)