title: Java - javax.json - Compile Error: "cannot find symbol" for .getValueType() - Can't seem to figure out why
body: <p>I have a database, and through my code I get my database into a JsonArray and start iterating through the JsonArray, (finding only JsonObjects). From there, I believe I have this setup so I can iterate through the properties of each JsonObject. However, each JsonObject contains Json Strings and Json Arrays. Right now, I'm experimenting so I tried to create a manual exception for the arrays, basically how I tried to have it setup is, only do your work, if you are dealing a Json String.  </p>
  
  <pre><code>import javax.json.Json;
  import javax.json.JsonReader;
  import javax.json.JsonStructure;
  import javax.json.JsonObject;
  import javax.json.JsonArray;
  import javax.json.JsonValue;
  import java.util.Iterator;
  import java.util.Collection;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class DataTest
  {
  public static void main(String[]args) throws IOException
  {
      String strValue = "";
      JsonReader reader = Json.createReader(new FileReader("Elements.JSON"));
      JsonObject jsonst = reader.readObject();
  
      JsonArray elements = jsonst.getJsonArray("Elements");
      for (int i = 0; i &lt; elements.size(); i++) 
      {
          JsonObject element = elements.getJsonObject(i);
          Collection&lt;String&gt; elementValues = element.keySet();
          Iterator&lt;String&gt; elementKeys = elementValues.iterator();
          while(elementKeys.hasNext())
          {
          //Error is over here!!!
              if(elementKeys.next().getValueType().equals(JsonValue.ValueType.STRING))
              {
                  String elementKey = (String)elementKeys.next();
                  strValue = element.getString(elementKey);
                  System.out.println(strValue);
              }
          }
      }
  
      reader.close();
  }
  }
  </code></pre>
  
  <p>I believe I have the right imports, however when I try to compile this the compiler gives me "cannot find symbol", at the .getValueType() method. (I left a comment stating "Error is over here!!!" in my code, the line with this method is right below that comment)</p>
  
  <p>I've also checked the format of the comparison, the following is copy and pasted from: <a href="http://www.programcreek.com/java-api-examples/index.php?api=javax.json.JsonString" rel="nofollow">http://www.programcreek.com/java-api-examples/index.php?api=javax.json.JsonString</a>
  if ((results.getValueType().equals(JsonValue.ValueType.STRING))</p>
  
  <p>Here is a small portion of my database: </p>
  
  <pre><code>{
  "Elements" : [
      {
      "name" : "Hydrogen",
      "Symbol" : "H",
      "atomicNumber" : "1",
      "electronegativity" : "2.2",
      "group" : "Hydrogen",
      "ionCharge1" : "1+",
      "ionCharge2" : "1-",
      "molarMass" : "1.01",
      "naturalState" : "Gas",
      "synthetic" : "false",
      "diatomic" : "true",
      "columnNumber" : "1",
      "row" : "1",
      "columnCode" : "IA",
  
      "nobleGasConfiguration" : [
          {
          "term:" : "No Noble Gas Configuration",
          "superScript" : "-"
          }
      ],
      "electronConfiguration" : [
          {
          "term" : "1s",
          "superScript" : "1"
          }
      ]
      }
  }
  </code></pre>
  
  <p>I suspect this may be to do with things such as subinterface, superinterfaces, implemented class, etc, etc. Essentially trying to use a method with something that does not have access to that method. However, as to my understanding this should work.</p>
  
  <p>Here is the api documents that you might need:</p>
  
  <p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html</a></p>
  
  <p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html</a></p>
  
  <p><a href="https://docs.oracle.com/javaee/7/api/javax/json/JsonValue.html" rel="nofollow">https://docs.oracle.com/javaee/7/api/javax/json/JsonValue.html</a></p>
  
  <p><a href="https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html" rel="nofollow">https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html</a></p>
  
  <p><a href="https://docs.oracle.com/javaee/7/api/javax/json/JsonArray.html" rel="nofollow">https://docs.oracle.com/javaee/7/api/javax/json/JsonArray.html</a></p>
  
  <p>To put my questions clearly down... Why is the compiler giving me a "cannot find symbol"? What do I have to change in my code to fix this?</p>
  
  <p>What programs, version, etc am I using?</p>
  
  <p>Notepad</p>
  
  <p>Command Prompt</p>
  
  <p>Java 8</p>
  
  <p>javax.json-1.0.jar</p>
  
  <p>Please keep the answers to javax.json and java.</p>