title: Java reflection question
body: <p>I am working on a project that uses reflection to get the fields of a running java application.</p>
  
  <p>I managed to get the fields, but I can not read or write to them. This is an example I found on the web:</p>
  
  <pre><code>Class aClass = MyObject.class
  Field field = aClass.getField("someField");
  MyObject objectInstance = new MyObject();
  Object value = field.get(objectInstance);
  field.set(objetInstance, value);
  </code></pre>
  
  <p>The problem is that I use classes from a running jar file, and the classes I try to manipulate are obtained from the classLoader. So instead of 'MyObject.class' I just have the '.class'. To get the 'MyObject' I tried to use a ClassLoader but that did not work.</p>
  
  <p>If I just use '.class':</p>
  
  <pre><code>Object value = field.get(theLoadedClass);
  </code></pre>
  
  <p>I will get this error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Can not set int field myClass.field to java.lang.Class
  </code></pre>
  
  <p>Thanks.</p>