Home > Back-end >  Null pointer exception, is solved
Null pointer exception, is solved

Time:09-16

Exception class is as follows:
 static class Point {
Public int x, y;

Public Point (int x, int y) {
this.x=x;
this.y=y;
}

Public Point (Point a) {
This. X=a.x;
This. Y=a.y;
}
}

//can't use recursive maze problem BFS
//the grid 0 to 1 obstacle
//@ return the return value is the pre on behalf of each point of the previous point
Static int aa, bb,
Static int [] [] dis=new int [] [] {{1, 0}, {1, 0}, {0, 1}, {0, 1}};

The static Point [] [] map (int [] [] the grid) {
Queue Q=new LinkedList<> (a);
Q.o ffer (new Point (0, 0));
Int n=grid. Length, m=grid [0]. Length;
Point [] [] pre=new Point [n] [m].
Boolean [] [] vis=new Boolean [n] [m].
While (! Q.i sEmpty ()) {
Point p=q.p oll ();
Vis [p.x] [p.y]=true;
If (p.x==n - 1 & amp; & P.y==m - 1)
Return the pre.
for (int i=0; I & lt; 4. I++) {
Int nx=p.x + dis [I] [0], ny=p.y + dis [I] [1];
If (nx & gt;=0 & amp; & Nx & lt; N & amp; & Ny & gt;=0 & amp; & Ny & lt; M & amp; & ! Vis/nx/ny & amp; & The grid (nx) [New York]==0) {
The pre [nx] [ny]=new Point (p.x, p.y);
Q.o ffer (new Point (nx, ny));
}
}
}
Return new Point [0] [0];
}


 

Case '3' :
Aa, bb, int
System. The out. Println (" please enter the maze of lines: ");
Int p=sc. NextInt ();
System. The out. Println (" please enter the column number of the maze: ");
Int q=sc. NextInt ();
Sc. NextLine ();
Int [] [] grid=new int [p] [q];
String row;
for(int i=0; I & lt; p; I++) {
System. The out. Println (" please enter the maze of the first "+ (I + 1) +" row (0 representatives can walk, 1 representative can't walk, separated by a space) : ");
The row=sc. NextLine ();
String [] y=row. The split (" ");
for(int j=0; J & lt; q; J++) {
The grid [I] [j]=Integer. ParseInt (y) [j].
}
}
Point [] [] pre=map (grid);
If (Objects. RequireNonNull (pre) [1] p/q - 1==null) {
System. The out. Println (" no exports of labyrinth ");
} else {
The grid [p - 1]] [q - 1=2;
Aa=pre [p - 1] [q - 1]. X.
Bb=pre [p - 1] [q - 1] y;
While (true) {
The grid/aa/bb=2;
Aa=pre/aa/bb. X;
Bb=pre/aa/bb] y;
If (==0 aa & amp; & Bb==0) {
The grid/aa/bb=2;
break;
}
}
System. The out. Println (grid);
}
break;

Is the idea of the bb=pre/aa/bb. Y; This line of Exception in the thread "is the main" Java. Lang. NullPointerException

CodePudding user response:

With the debug code can solve the problem, why must turn to the Internet?
  • Related