Originariamente inviato da d@ny1983
sto facendo una Swing ed ho un problema con i tipi di oggetto ora vi scrivo la riga di codice che mi da problemi

Integer a =(Integer)(table.getValueAt(i,j));
res[i][j]=a.intValue();


dove
table è una Jtable
res è un int[][]
table.getValueAT(i,j) restituisce un Object secondo le api

mi da un errore che java.lang.String nn puo' essere castato ad Integer perchè da questo errore se il metodo restituisce un Object??
Restituisce Object perché tecnicamente deve poter restituire un oggetto qualunque ... che è appunto sicuramente un "Object".
Poi quasi sicuramente (e se non hai implementato un tuo table model) l'oggetto reale nella cella è un String.

Ma non puoi passare da String a Integer con un cast, perché è un cast non valido in quanto String e Integer non sono sulla stessa "linea di ereditarietà".

Se vuoi ottenere un int (primitivo) da un String fai:

int a = Integer.parseInt (stringa)

e naturalmente dovresti catturare l'eccezione NumberFormatException.