title: How to call GoogleCloudVision and store it in a user define object in arraylist
body: <p>I've been trying to call the detectImageLabels method and get the results into the user-defined array ObjectLabel, but I keep getting errors. I have no idea what to do. The labelImage method calls on the getFile method in main, to get the absolute path of the file, to then input the path into the GoogleVision. Is supposed to output an array of labels from the image file chosen by the user. For example, if the user picked a bird photo, it should return an array with values like bird, feathers, flying, wings, nature. Maybe I handled the throw Exceptions incorrectly in main.</p>
  <pre><code>public static void labelImage(String filename) throws IOException, InterruptedException {
          String userFile = filename;
          JFrame img = new JFrame();
          ImageIcon icon = new ImageIcon(userFile);
          JLabel label = new JLabel(icon);
          img.add(label);
          img.pack();
          img.setVisible(true);
          ArrayList&lt;ObjectLabel&gt; labels = GoogleCloudVision.detectImageLabels(userFile);
          System.out.println(labels);
  </code></pre>
  <p>Then this is my Main which Idk if I handled the exception correctly.</p>
  <pre><code>String userFile = getFilename();
          try {
              labelImage(userFile);
          } catch (IOException e) {
              e.printStackTrace();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
  </code></pre>
  <p>Then this is my ObjectLabel Method</p>
  <pre><code>class ObjectLabel {
  
      private String labels;
      private double confidence;
  
      public ObjectLabel(String labels, double confidence) {
          this.labels = labels;
          this.confidence = confidence;
      }
  
      public String getlabels() {
          return labels;
      }
  
      public void setLabels(String labels) {
          this.labels = labels;
      }
  
      public double getConfidence() {
          return confidence;
      }
  
      public void setConfidence(double confidence) {
          this.confidence = confidence;
      }
  
      @Override
      public String toString() {
          return &quot;ObjectLabel{&quot; +
                  &quot;labels='&quot; + labels + '\'' +
                  &quot;, confidence=&quot; + confidence +
                  '}';
      }
  }
  </code></pre>
  <p>This is the GoogleCloudVision</p>
  <pre><code> ArrayList&lt;ObjectLabel&gt; results = new ArrayList&lt;&gt;();
  
          // create the ImageAnnotatorClient to make the call to Google Cloud Vision
          try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create(imageAnnotatorSettings)) {
              // call the Google Cloud Vision service to detect the labels
              BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
  
              // process the results
              for (AnnotateImageResponse res : response.getResponsesList()) {
                  // if an error occurred, print it and return an empty list
                  if (res.hasError()) {
                      System.err.println(&quot;Error: &quot; + res.getError().getMessage());
                      return results;
                  } // end if error
  
                  // put the labels into our results ArrayList
                  for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
                      results.add(new ObjectLabel(annotation.getDescription(),
                              annotation.getScore()));
                  } // end for each annotation
              } // end for each response
          } // end try with resources
          return results;
      } // end labelImage
  </code></pre>
  <p>Then this is the error I'm getting</p>
  <pre><code>java.nio.file.NoSuchFileException: C:\Users\DELL Laptop\Downloads\Exam3Starter\src
      at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
      at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
      at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
      at java.base/sun.nio.fs.WindowsDirectoryStream.&lt;init&gt;(WindowsDirectoryStream.java:86)
      at java.base/sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(WindowsFileSystemProvider.java:533)
      at java.base/java.nio.file.Files.newDirectoryStream(Files.java:544)
      at GoogleCloudVision.findJsonCredentialsFile(GoogleCloudVision.java:51)
      at GoogleCloudVision.detectImageLabels(GoogleCloudVision.java:80)
      at SeeFood.labelImage(SeeFood.java:61)
      at SeeFood.main(SeeFood.java:93)
  </code></pre>