In the following coding dub is an object of a class and it comes in a java List. What I'm trying to do is to get the unique dates and no of clicks for a day from the database. Please see the highlighted part. For the fost times it goes to there(because there are no elements), but throws a null pointer exception.
public List <Report> dub;
public List <String> detailsDateStore=null;
public List <String> detailsCountStore=null;
//assigning db values to the dub
dub=database.findipRecords(date1, date2);
try
{
if(dub!=null)
{
for (int i = 0; i < dub.size(); i++) {
String tempdate=dub.get(i).getDate().toString();
int tempCount=Integer.parseInt(dub.get(i).getClicks().toString());
int find=0;
int position=0;
//Check if the date already exists
if(detailsDateStore!=null)
{
for(int j=0;j<detailsDateStore.size();j++)
{
if((detailsDateStore.get(j).equals(tempdate)))
{
//if the date already exists increase "find"
position=j;
find++;
}
}
//If find is not greater than 0
if(find==0)
{
//store the date
detailsDateStore.add(i, tempdate);
detailsCountStore.add(i,detailsCountStore.get(i)+tempCount);
}
else
{
detailsCountStore.add(position,detailsCountStore.get(position)+tempCount);
}
}
else
{
[color=#FF0000]detailsDateStore.add(tempdate);
detailsCountStore.add(String.valueOf(tempCount));[/color]
}
}}
else
{
System.out.println("Dub is null");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Do appreciate your help and support. Thank you in advance.

New Topic/Question
Reply




MultiQuote




|