|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Feb 2006
Messaggi: 11
|
[Java] Null Pointer Exception
Ciao, mi sapete dire cosa c'è che non va in questo codice ?
Codice:
import java.util.*;
public class Matrice {
/**
* @param args
*/
public static void main(String[] args) {
int[][] M = {
{ 0, 1, 1 },
{ 1, 0, 0 },
{ 1, 0, 0 }
};
int n = M.length; // n.ro righe
AdjacencyList[] aList = new AdjacencyList[n];
for(int i = 0; i < n ; i++)
for(int j = 0; j < n; j++)
if(M[i][j] == 1)
aList[i].add(new Integer(i));
}
class AdjacencyList {
private LinkedList<Integer> list = new LinkedList<Integer>();
public void add(Integer item) {
list.add(item);
}
}
}
All'esecuzione mi da errore java.lang.NullPointerException |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Feb 2002
Città: Modena
Messaggi: 592
|
Prova così:
Codice:
package javaapplication3;
import java.util.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
int[][] M = {
{ 0, 1, 1 },
{ 1, 0, 0 },
{ 1, 0, 0 }
};
int n = M.length; // n.ro righe
AdjacencyList[] aList = new AdjacencyList[n];
for(int i = 0; i < n ; i++){
aList[i] = new AdjacencyList();
for(int j = 0; j < n; j++)
if(M[i][j] == 1)
aList[i].add(new Integer(i));
}
}
static class AdjacencyList {
private LinkedList<Integer> list = new LinkedList<Integer>();
public void add(Integer item) {
list.add(item);
}
}
}
Ultima modifica di vegeta83ssj : 07-10-2008 alle 19:44. |
|
|
|
|
|
#3 |
|
Junior Member
Iscritto dal: Feb 2006
Messaggi: 11
|
ottimo, grazie mille
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:40.



















