DBSCAN implementation

I am trying to implement the DBSCAN (Density based spatial clustering application with noise, partition based clustering algorithm ). But after the inpute (a databse) is taken it shows NullPointerException(). why?if anybody have the DBSCAN implementation please send to me
[286 byte] By [itsnava4u@yahoo.co.ina] at [2007-11-27 7:08:15]
# 1

> I am trying to implement the DBSCAN (Density based

> spatial clustering application with noise, partition

> based clustering algorithm ). But after the inpute (a

> databse) is taken it shows NullPointerException().

> why?

Kind of hard to figure out without code. I don't know about anyone else, but I left my mind-reading hat back at the office.

petes1234a at 2007-7-12 18:59:44 > top of Java-index,Java Essentials,Java Programming...
# 2

I am trying to implement the DBSCAN (Density based spatial clustering application with noise, partition based clustering algorithm ). But after the inpute (a databse) is taken it shows NullPointerException(). why?

if anybody have the DBSCAN implementation please send to me

I attached herewith the code

/*********************************************************************/

import java.io.*;

import java.awt.*;

import java.awt.event.*;

import java.lang.Math;

import javax.swing.*;

import java.applet.*;

import java.lang.String;

import java.util.*;

class obj

{

public static int N=0,U=1,C=2;

public int id=1,catg,x,y,p;

public obj(){} /*ARGUMENT CONSTRUCTOR*/

public obj(int a,int b)

{

x=a;

y=b;

id=1;

catg=U;

} /*ARGUMENT CONSTRUCTOR*/

public void mark_cid(int a){id=a;} /* MARK THE CLUSTER_ID */

public void mark_catg(int a){catg=a;} /*MARK THE CATEGORY */

public int getx(){return x;}

public int gety(){return y;}

public int getcid(){return id;}

public int getcatg(){return catg;}

}

public class dbscan extends obj

{

public dbscan()throws IOException

{

obj db[]=new obj[400];

int c=0,mpn=4;

double eps=3.0;

c=file_read(db);

System.out.println("\n\n\n Total number of object : "+c);

try

{

/*for(int i=0;i<400;i++)

db.mark_catg(U);*/

for(int i=0;i<c;i++)

{

if(db.getcatg()==U)

expand_cls(db,db,eps,mpn);

}

display(db,c);

}

catch(NullPointerException e){System.out.print("ERROR : "+e);}

}

double dist(obj o1,obj o2)

{

double d1=o1.x-o2.x;

double d2=o1.y-o2.y;

return(Math.sqrt(d1*d1+d2*d2));

}

int expand_cls(obj o,obj db[],double eps,int mpt)

{

//try{

obj nbhd[]=new obj[100] ;

int j,i;

LinkedList candi= new LinkedList();

obj candi_obj=new obj();

obj crnt_obj=new obj();

for(i=0,j=0;i<100;i++)

{

if(dist(o,db)><=eps && dist(o,db)>0.0)

{

nbhd[j]=db;

j++;

}

}

if(j<mpt)

{o.mark_catg(N);}

else

{

o.mark_cid(id);

for(i=0;i<j;i++)

{

if(nbhd.getcatg()==N)

nbhd.mark_cid(id);

else

{

nbhd.mark_cid(id);

nbhd.mark_catg(C);

candi.addLast(nbhd);

while(!candi.isEmpty())

{

for(i=0;i<100;i++)

nbhd=null;

for(i=0,j=0;i<100;i++)

{

if(dist(crnt_obj,db)><=eps && dist(crnt_obj,db)>0)

{nbhd[j++]=db;}

}

if(j>mpt)

{

for(i=0;i<j;i++)

{

crnt_obj=nbhd;

if(crnt_obj.getcatg()==N)

{

crnt_obj.mark_cid(id);

crnt_obj.mark_catg(C);

}

if(crnt_obj.getcatg()==U)

candi.addLast(crnt_obj);

}//END OF FOR

}//END OF IF

}//END OF WHILE

}//END OF ELSE

}//END OF FOR

id++;

}

//}

//catch(NullPointerException e){System.out.println("ERROR : "+e);}

return 0;

}

int file_read(obj db[])throws IOException

{

int i,counter=1,k=0;

int temp[]=new int[6];

try{

FileInputStream fin=new FileInputStream("d:\\j2sdk\\bin\\a.txt");

do

{

i=fin.read();

if(i !=-1)

{

System.out.print((char)i);

}

if((char)i==' '||(char)i=='\n'||(char)i=='\t')

{

//for(int j=0;j<k;j++)System.out.print("\ntemp = "+(char)temp[j]+" ");

counter++;

k=0;

}

else

{

temp[k]=(char)i;

k++;

}

}while(i !=-1);

}

catch(FileNotFoundException e)

{System.out.println(e.getMessage()+"File not found");}

catch(ArrayIndexOutOfBoundsException e)

{System.out.println("Error : "+e.getMessage());}

return counter;

}

void display(obj db[],int counter)

{

for(int i=0;i<counter;i++)

{

int x=db.getx();

int y=db.gety();

int id=db.getcid();

if(id!=-1)

System.out.print(db);

}

}

/*

int expand_cls(obj o,obj db[],double eps,int mpnt,int counter)

{

try{

obj nbhd[]=new obj[400] ;

int i,j=0;

double di;

LinkedList candi= new LinkedList();

obj candi_obj=new obj();

for(i=0;i<counter;i++)

nbhd=null;

for(i=0;i<counter;i++)

{

di=0.0;

di=dist(o,db);

if(di><=eps && di>0.0)

{nbhd[++j]=db;}

if(j<mpnt)

{o.mark_catg(N);}

else

{

o.mark_cid(id);

o.mark_catg(C);

for(i=0;i<j;i++)

{

nbhd.mark_cid(id);

nbhd.mark_catg(C);

candi.addLast(nbhd);

}

while(!candi.isEmpty())

{

for(i=0;i<100;i++)

nbhd=null;

j=0;

for(i=0;i<counter;i++)

{

di=dist(candi_obj,db);

if(di><=eps && di>0)

{nbhd[j++]=db;}

}

if(j>mpnt)

{

obj ncandi_obj;

for(i=0;i<j;i++)

{

ncandi_obj=nbhd;

if(ncandi_obj.getcatg()==N)

{

ncandi_obj.mark_cid(id);

ncandi_obj.mark_catg(C);

}

if(ncandi_obj.getcatg()==U)

candi.addLast(ncandi_obj);

}//END OF FOR

}//END OF IF

}//END OF WHILE

}//END OF ELSE

}//END OF FOR

id++;

}

catch(NullPointerException e){System.out.println("ERROR : "+e);}

return 0;

}

*/

public static void main(String param[]) throws IOException

{dbscan a=new dbscan();}

}>

itsnava4u@yahoo.co.ina at 2007-7-12 18:59:44 > top of Java-index,Java Essentials,Java Programming...
# 3

The stack trace tells you which line of this code the exception was thrown from.

Somewhere on that line you are using an object reference which is null. Don't do that. It will not be hard to find, but you do have to look. Posting such a trivial problem here and waiting for an answer that will probably never arrive is just a waste of your time.

ejpa at 2007-7-12 18:59:44 > top of Java-index,Java Essentials,Java Programming...