I got a file with 6 line in it andimport java.io.*; public class Prim { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); .... public static tempEdge [] tedges; .... public Graph graph; private static int tempi = 0, one, two, size; public void buildTable(String file){ n = 10;//menu.numOfNodes(); tedges = new tempEdge[n*(n-1)/2]; try{ BufferedReader input = new BufferedReader(new FileReader(file)); while(input.ready()) { String tmp = input.readLine(); String[] newPoint = tmp.split(" "); int p1 = Integer.parseInt(newPoint[0]); int p2 = Integer.parseInt(newPoint[1]); int dis = Integer.parseInt(newPoint[2]); tedges[tempi] = new tempEdge(p1,p2,dis); System.out.println(tedges[tempi].firstPoint()); System.out.println(tedges[tempi].secondPoint()); System.out.println(tedges[tempi].distance()); tempi++; } } catch(IOException e) { System.out.println("Error, file does not exist"); } prims(); } //create a minal spanning tree public static void prims() { n = 5;//menu.numOfNodes(); //set size of the array which store different things Graph = new int[n+1][n+1]; Tree = new int[n+1][3]; near = new int[n+1]; while(tedges != null){ for(int i=0;i<=tedges.length;i++){ //tempEdge e = tedges[i]; one = tedges[i].firstPoint(); System.out.println("1"); two = tedges[i].secondPoint(); size = tedges[i].distance(); if((one!=two)&&(one<two)) { Graph[one][two] = Graph[two][one] = size; if(Graph[one][two] == 0 ) Graph[two][one] = Graph[one][two] = 7001; } if(one==two) Graph[one][two]=7001; } } getMinKL(); mincost = Graph[k][l]; Tree[1][1] = l; Tree[1][2] = k; for(int i=1; i<=n; i++) near[i] = (Graph[i][l]<Graph[i][k])?l:k; near[k] = near[l] = 0; for(int i=2; i<n; i++) { int j = getMin(); Tree[i][1] = j; Tree[i][2] = near[j]; mincost = mincost+Graph[j][near[j]]; near[j] =0; for (int k=1; k<=n; k++) if( (near[k] !=0) && Graph[k][ near[k] ]> Graph[k][j] ) near[k] =j; } tri.createNode(); } ....... public static void main (String[] args) throws IOException { Prim prim = new Prim(); prim.buildTable("3Dtriangle.txt"); System.out.println("Solution : "); for (int i = 1; i<=n; i++) { if( (Tree[i][1]!=0) && (Tree[i][2] !=0) ) System.out.println(Tree[i][1] + "-" +Tree[i][2]); System.out.println(Graph[Tree[i][1]][Tree[i][2]]); } } }

After i run the code, it shows

1

2

50

1

3

Exception in thread "main" java.lang.NullPointerException

60

1

4

70

2

3

80

2

4

40

3

4

60

1

1

1

1

1

1

at triangle_projection.Prim.prims(Prim.java:69)

at triangle_projection.Prim.buildTable(Prim.java:55)

at triangle_projection.Prim.main(Prim.java:178)

can anyone please help me to solve it?

Thank you