I have a class, server. It has a private field f of type class fg. It in turn has a private field e of type int. I want to modify e, but I can't modify those classes. Succinctly stated, it's: server.(fg)f.(int).e
I tried this code, but I'm a bit rusty on my Java, let alone reflection. Line 4 throws a NullPointerException, because it looks like Line 3 isn't actually working like I expect.
Field fieldf = server.getClass().getDeclaredField("f");
fieldf.setAccessible(true);
Class classf = (Class) fieldf.get(server);
Field e = classf.getDeclaredField("e"); // Throws NullPointerException
e.setAccessible(true);
e.set(e, anumber);
Does anyone with more experience with reflection have any suggestions?