import java.awt.*;  
import java.awt.event.*;    
import javax.swing.*;   
import java.util.*; 
import java.io.*;   
import java.text.*; 
import java.util.regex.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

class Clustering1 
{
    public static void main(String[] args) throws IOException, FileNotFoundException
    {
        int diff_matrix[][] = new int[500][500];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the data file name\n");
        String fname=br.readLine();       
        File file = new File(fname);
        if (file.exists())
            {
            FileReader fr = new FileReader(file);   
            LineNumberReader ln = new LineNumberReader(fr);

             int n = 0;

             while (ln.readLine() != null)  
             n++;
             ln.setLineNumber(1);
             for(int i=1;i<n-1;i++)
                {
                 for(int j=1;j<n-1;j++)
                    {
                     if(i!=j)
                         {


                                 ln.setLineNumber(i);
                                String line1=ln.readLine();
                                Pattern pat = Pattern.compile("[ ,]");
                                 ln.setLineNumber(j);
                                String line2=ln.readLine();

                                 String str1[]=pat.split(line1);
                                 String str2[]=pat.split(line2);
                                 int count=0;
                                 int s=0;
                                for(int p=0; p < str1.length; p++)
                         {
                                     if(str1[p].equals(str2[p]))
                                         count=count+1;
                         }
                         diff_matrix[i-1][j-1]=count;
                     }
                         else
                             diff_matrix[i-1][j-1]=0;
                     }
                    }
                    for(int i=0;i<n-2;i++)
                {
                        System.out.println();
                        for(int j=0;j<n-2;j++)
                    {
                            System.out.print(diff_matrix[i][j]+"\t");
                    }
                }     



        int neigh_matrix[][] = new int[500][500];
        int nm=0;
        int k=1;
        int min_matrix[]=new int[500];
        for(int i=0;i<n-1;i++)
                {           
            int min=diff_matrix[i][k];
            for(int j=0;j<n-1;j++)
                { 
            if(i!=j){
                    if(min>diff_matrix[i][j])
                        {
                        min=diff_matrix[i][j];
                            }
                        }
                    }
                    min_matrix[i]=min;
                    k=0;
                }
                for(int i=0;i<n-1;i++)
                {
                    neigh_matrix[i][nm]=i+1;
                    for(int j=0;j<n-1;j++)
                    {
                        if(min_matrix[i]==diff_matrix[i][j])
                        {
                            neigh_matrix[i][++nm]=j+1;

                        }
                    }
                }   
                for(int i=0;i<n-1;i++)
                {
                    System.out.println();
                    for(int j=0;j<neigh_matrix[i].length;j++)
                        System.out.println(neigh_matrix[i][j]+"\t");
                }

                int clusters[][] = new int[500][500];


        }
        else
        {
            System.out.println("File is not exist");
        }
    }
}

i am not getting correct output.. can u solve it

my error is:Exception in thread "main" java.lang.NullPointerException
        at java.util.regex.Matcher.getTextLength(Matcher.java:1127)
        at java.util.regex.Matcher.reset(Matcher.java:284)
        at java.util.regex.Matcher.<init>(Matcher.java:205)
        at java.util.regex.Pattern.matcher(Pattern.java:879)
        at java.util.regex.Pattern.split(Pattern.java:988)
        at java.util.regex.Pattern.split(Pattern.java:1050)
        at Clustering.main(Clustering.java:39)

That error tells you exactly what is the problem and where to look:
Exception in thread "main" java.lang.NullPointerException
....
at Clustering.main(Clustering.java:39)

At the Clustering.java file line 39, in the method method, you are using something which is null

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.