title: Reflection and NullPointerException with static fields/methods?
body: <p>I am trying to use reflection to access a method and variable that I do not want inherited by an object. I receive a null pointer exception with these <em>static</em> variables, and I cannot notice anything I have missed. I would appreciate help in resolving the exception :) </p>
  
  <p>Am I missing any lines, or not using Alien.class when I need to?</p>
  
  <p>Main class:</p>
  
  <pre><code>public class Main {
  public static void main(String[] args)
  {
      System.out.println("Starting process of alien creation...");
      Alien alien_1 = new Alien("Bob", 5, (float) 45.3, AlienType.REACTIVE);
      Alien alien_2 = new Alien("Lilly", 7, (float) 49.8, AlienType.FRIENDLY);
      System.out.println("\n" + alien_1.getName());
      alien_1.setName("Carl");
      System.out.println(alien_1.getName());
      Method getNameList = null;
      Field nameList = null;
      try {
          getNameList = Alien.class.getClass().getDeclaredMethod("getNameList");
      } catch (NoSuchMethodException e) {
          System.out.println("ERROR - Method \"getNameList\" does not exist!");
      } catch (SecurityException e) {
          System.out.println("ERROR - Method \"getNameList\" cannot be used!");
      }
  
      try {
          nameList = Alien.class.getClass().getDeclaredField("alienNames");
      } catch (NoSuchFieldException e) {
          System.out.println("ERROR - Field \"nameList\" does not exist!");
      } catch (SecurityException e) {
          System.out.println("ERROR - Field \"nameList\" cannot be used!");
      }
  
      getNameList.setAccessible(true);
      nameList.setAccessible(true);
      try {
          ArrayList&lt;String&gt; returnValue = (ArrayList&lt;String&gt;) getNameList.invoke(new Alien(), nameList);
      } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Alien class:</p>
  
  <pre><code>public class Alien 
  {
      public void getAndPrintType(AlienType type)
      {
          switch (type) 
          {
              case FRIENDLY : System.out.print(", type - FRIENDLY.\n"); break;
              case SCARY : System.out.print(", type - SCARY.\n"); break;
              case REACTIVE : System.out.print(", type - REACTIVE.\n"); break;
          }
      }
  
      String name;
      int age;
      float weight;
      AlienType type;
  
      int totalAliens;
  
      public static ArrayList&lt;String&gt; alienNames = new ArrayList&lt;String&gt;();
      ArrayList&lt;Integer&gt; alienAges = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Float&gt; alienWeights = new ArrayList&lt;Float&gt;();
      ArrayList&lt;AlienType&gt; alienTypes = new ArrayList&lt;AlienType&gt;();
  
      float totalWeight;
  
      public Alien(String name, int age, float weight, AlienType type)
      {
          System.out.print("You have created an alien of attributes: ");
          System.out.print("name - " + name );
          System.out.print(", age - " + String.valueOf(age));
          System.out.print(", weight - " + String.valueOf(weight) + " pounds");
          getAndPrintType(type);
          this.name = name;
          this.age = age;
          this.weight = weight;
          this.type = type;
  
          // Global impact
          totalAliens++;
          alienNames.add(name);
          alienAges.add(age);
          alienWeights.add(weight);
          alienTypes.add(type);
      }
  
      public Alien() {}
      private static String getNameList()
      {
          String returnValue = "";
          for (String nameLocal : alienNames)
          {
              if (!(alienNames.get((alienNames.size() - 1)).equals(nameLocal)))
              {
                  returnValue += nameLocal + ", ";
              }
              else
              {
                  returnValue += nameLocal;
              }
          }
          return returnValue;
      }
  }
  </code></pre>