Przykład

public GetDeclaredField_Example() {
super();
}

public void setValue( int value ) {
this .value = value;
}

public int getValue() {
return value;
}

private int value;

public static void main( String[] args) {
try {
Field field = GetDeclaredField_Example.class.getDeclaredField( "value" ); //$NON-NLS-1$
GetDeclaredField_Example obj = new GetDeclaredField_Example();
field.set( obj, new Integer( 1 ) );
System.out.println( obj.getValue() );
} catch (SecurityException e) {
System.out.println( "Nie można uzyskać dostępu do pola value" ); //$NON-NLS-1$
} catch (NoSuchFieldException e) {
System.out.println( "Brak pola value" ); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} catch (IllegalAccessException e) {
System.out.println( "Nie można uzyskać dostępu do prywatnego pola value" ); //$NON-NLS-1$
}
}

Rozwiązanie
Zamiast metody getDeclaredField() dla zakodowanej na stałe nazwy pola użyj bezpośredniego dostępu do pola.

public GetDeclaredField_Solution() {
super();
}

public void setValue( int value ) {
this .value = value;
}

public int getValue() {
return value;
}

private int value;

public static void main( String[] args) {
GetDeclaredField_Example obj = new GetDeclaredField_Example();
obj.setValue( 1 );
System.out.println( obj.getValue() );
}