title: Syntax error in Eclipse when using static getNames method of JSONObject Java class
body: <p>I'm trying to return all of the names that have been provided to a JSONObject class (as in, all of the keys in their own array, without their associated values). My code is currently as follows:</p>
  
  <pre><code>String names[] = new String[10];
  names = JSONObject.getNames(jsonObj);
  </code></pre>
  
  <p>The method I'm trying to get the array from is this:</p>
  
  <pre><code>public static String[] getNames(JSONObject jo) {
      int length = jo.length();
      if (length == 0) {
          return null;
      }
      Iterator iterator = jo.keys();
      String[] names = new String[length];
      int i = 0;
      while (iterator.hasNext()) {
          names[i] = (String)iterator.next();
          i += 1;
      }
      return names;
  }
  </code></pre>
  
  <p>And this is the error I'm getting:</p>
  
  <pre><code>The method getNames(JSONObject) is undefined for the type JSONObject
  </code></pre>
  
  <p>However, if I set my code to deliberately return and assign it to a variable of the wrong type:</p>
  
  <pre><code>int inames = JSONObject.getNames(jsonObj);
  </code></pre>
  
  <p>Highlighting either the JSONObject part or the jsonObj parameter of that above line cause Eclipse to display the following error:</p>
  
  <pre><code>Type mismatch: cannot convert from String[] to int
  </code></pre>
  
  <p>Whereas highlighting the getNames method still provides the same error as before.</p>
  
  <p>What am I to garner from this? Eclipse seems to know that the method is there, since it knows its correct return type, yet it's claiming that the method is undefined in the class.</p>