Results 1 to 3 of 3
Thread: How to count list size?
- 02-18-2013, 08:22 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
How to count list size?
Hi
I have a list and i have added class object to list. My code is as follows
public class HeaderReason
{
private String sRejCode;
private String sDescription;
public void setCode(String sCode)
{
sRejCode = sCode;
}
public String getCode()
{
return sRejCode;
}
public void setDescription(String sDesc)
{
sDescription = sDesc;
}
public String getDescription()
{
return sDescription;
}
}
public class HeaderReasons extends ArrayList<HeaderReason>
{
}
I have added items to list as below code
objHReason = new HeaderReason();
objHReason.setCode(sCode.toString());
objHReason.setDescription("Rejected for more than one reason.");
lstHReasons.add(objHReason);
When return lstHReasons and check the size it is showing me as 2 but it contains only one record at [0]. When i loop through this list as getting error as nullpointer
stmt = conSqlServer.prepareStatement(sqlQuery);
for(int i = 0; i < lstHReasons.size(); i++)
{
stmt.setString(1, sEstdFileRefNo);
stmt.setString(2, lstHReasons.get(i).getCode());
stmt.setString(3, lstHReasons.get(i).getDescription());
stmt.addBatch();
}
stmt.executeBatch();
How to loop through this list and add contents to database?
Thanks
- 02-18-2013, 04:28 PM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Re: How to count list size?
Hi athar,
The code is not complete enough to say where your issue lies but you said you have added items to the array as opposed to just a single object.
Can you provide the complete code you have used to add the items to the list.
Regards.
- 02-18-2013, 05:00 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How to count list size?
Please wrap your code in [code] tags [/code] so that it retains its formatting.
Many of us won't bother reading unformatted code.
Next, please post the full exception including stack trace, highlighting the line on which it is thrown.
Finally, presuming it's this line:
can you post the code (as Ronin asks) in which you populate the list?Java Code:stmt.setString(2, lstHReasons.get(i).getCode());
Looks to me like somewhere you are adding a null into the list.Please do not ask for code as refusal often offends.
Similar Threads
-
count every 45 records and prfix the count number
By dkr786 in forum New To JavaReplies: 8Last Post: 02-15-2013, 07:31 PM -
count elements in linked list recursively!
By hussien in forum New To JavaReplies: 2Last Post: 11-23-2012, 05:17 PM -
How would I count number of nodes in linked list?
By colerelm in forum New To JavaReplies: 2Last Post: 10-17-2011, 06:26 AM -
java 2 dimensional no size list
By rblmvs in forum New To JavaReplies: 6Last Post: 04-03-2011, 10:11 AM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks