这是我的代码:
public class Main {
private int[][] AR;
private int[][] AG;
private int[][] Sink;
private int[][] RR;
private int[][] RP;
private int n;
//int n = 3;
public void initialization(int n) {
initAR(n);
initAG(n);
initSink(n);
initRR(n);
initRP(n);
}
public void initAR(int n) {
this.AR = new int[n][n];
}
public void initAG(int n) {
this.AG = new int[n][n];
}
public void initSink(int n) {
this.Sink = new int[n][n];
}
public void initRR(int n) {
this.RR = new int[n][n];
}
public void initRP(int n) {
this.RP = new int[n][n];
}
public int multi_unit_fun(int process, int resource) {
boolean IsAllocated = false;
for (int i = 0;i < n;i++) {
if (AG[resource][i] == 1) {
IsAllocated = true;
break;
}
}
if (!IsAllocated) {//resource is available
AG[resource][process] = 1;
Sink[resource][process] = 1;
RP[resource][process] = 1;
return 0;
}
else {//resource is not available.
if (Sink[resource][process] == 1) {
return 1;
}
else {
blockProcess(process, resource, n);
return 2;
}
}
}
public int[][] getSink() {
return this.Sink;
}
public void blockProcess(int process, int resource, int n) {
AR[process][resource] = 1;
int sum = 0;
for (int i = 0;i < n;i++) {
sum += AG[i][process];
}
if (sum > 0) {
for (int k = 0; k < n;k++) {
if (Sink[k][process] == 1) {
for (int j = 0;j < n;j++) {
Sink[k][j] = Sink[resource][j];
RR[k][j] = RR[k][j] | RR[resource][j];
RP[k][j] = RP[k][j] | RP[resource][j];
}
}
}
}
}
}
当代码在&#34; AG执行时[资源] [进程] = 1&#34;有一个例外说&#34; NullPointerException&#34;。我初始化矩阵AR时似乎有问题。但我无法弄清楚问题是什么。