3 Replies - 1160 Views - Last Post: 26 February 2009 - 10:44 PM Rate Topic: -----

#1 chitrikaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-January 09

Java Null pointer Exception

Posted 26 February 2009 - 04:50 AM

Hi,

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Java Null pointer Exception

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Java Null pointer Exception

Posted 26 February 2009 - 11:34 AM

I dont see anywhere you are initialising your List. I dont know what type of List you want to do, but in your code you need to do somthing like the below for all your list.
detailsCountStore = new ArrayList<String>();

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Java Null pointer Exception

Posted 26 February 2009 - 06:23 PM

The Java run time will tell you at which line you have the Null Pointer Exception
that should give you a hint
Was This Post Helpful? 0
  • +
  • -

#4 chitrikaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-January 09

Re: Java Null pointer Exception

Posted 26 February 2009 - 10:44 PM

Yeah..Thanks guys. I fixed it. (dance)
:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1