Hallo zusammen,
ich bekomme beim printen von meinem array diese Fehlermeldungen und ich denke es liegt an der Zuweisung von den Werten also an der Methode setValues().
Ich weiß aber nicht warum, könnt ihr mir helfen?
Vielen Dank
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Implementation.Adjazenmatrix.setValues(Adjazenmatrix.java:14)
at Implementation.Adjazenmatrix.main(Adjazenmatrix.java:57)
ich bekomme beim printen von meinem array diese Fehlermeldungen und ich denke es liegt an der Zuweisung von den Werten also an der Methode setValues().
Ich weiß aber nicht warum, könnt ihr mir helfen?
Vielen Dank
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Implementation.Adjazenmatrix.setValues(Adjazenmatrix.java:14)
at Implementation.Adjazenmatrix.main(Adjazenmatrix.java:57)
Java:
package Implementation;
public class Adjazenmatrix {
//Attribute
int n; // Anzahl der Knoten
private double[][] adjazenmatrix = new double[n][n];
public Adjazenmatrix(int n) {
this.n = n;
}
public void setValues(int row, int column, double value) {
adjazenmatrix[row][column]= value;
}
public void printMatrix() {
for (int i = 0; i<=adjazenmatrix.length;i++) {
for(int j=0; j<=adjazenmatrix[i].length;j++) {
System.out.print(adjazenmatrix[i][j]);
}
}
}
boolean isConnected (int i, int j) {
boolean connected = false;
if(adjazenmatrix[i][j]!=0.0) {
connected = true;
}
else {
connected = false;
}
return connected;
}
//void complement() {
// }
//gibt es einen Pfad im Graphen von dem Knotten i zum Knoten j?
//boolean isReachable(int i, int j) {
//}
public static void main(String[] args) {
//ungerichtete Matrix
Adjazenmatrix a1 = new Adjazenmatrix(5);
//0te Reihe
a1.setValues(0,1,1.0);
a1.setValues(0,4,1.0);
//not connected, value 0.0
a1.setValues(0,0,0.0);
a1.setValues(0,2,0.0);
a1.setValues(0,3,0.0);
//1te Reihe
a1.setValues(1,0,1.0);
a1.setValues(1,2,1.0);
a1.setValues(1,4,1.0);
//not connected, value 0.0
a1.setValues(1,1,0.0);
a1.setValues(1,3,0.0);
//2te Reihe
a1.setValues(2,1,1.0);
a1.setValues(2,3,1.0);
a1.setValues(2,4,1.0);
//not connected, value 0.0
a1.setValues(2,0,0.0);
a1.setValues(2,2,0.0);
//3te Reihe
a1.setValues(3,2,1.0);
a1.setValues(3,4,1.0);
//not connected, value 0.0
a1.setValues(3,0,0.0);
a1.setValues(3,1,0.0);
a1.setValues(3,3,0.0);
//4te Reihe
a1.setValues(4,0,1.0);
a1.setValues(4,1,1.0);
a1.setValues(4,2,1.0);
a1.setValues(4,3,1.0);
//not connected, value 0.0
a1.setValues(4,4,0.0);
a1.printMatrix();
}
}