title: Unable to get contents of clipboard (Java)
body: <p>I am running the following code:</p>
  
  <pre><code>String clipBoardText;
  
  public String getAllTextOfPage() {
      StringSelection stringSelection = new StringSelection(null);
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
              stringSelection, null);
  
      Robot r = null;
      try {
          r = new Robot();
      } catch (AWTException e) {
          e.printStackTrace();
      }
      r.keyPress(KeyEvent.VK_CONTROL);
      r.keyPress(KeyEvent.VK_A);
      r.keyRelease(KeyEvent.VK_A);
      try {
          Thread.sleep(1000);
      }
      catch (InterruptedException ie) {
          System.out.print(ie.getLocalizedMessage());
      }
  
      r.keyPress(KeyEvent.VK_C);
      r.keyRelease(KeyEvent.VK_CONTROL);
      r.keyRelease(KeyEvent.VK_C);
  
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  
          try {
              clipBoardText = (String)clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor);
              System.out.println(clipBoardText);
          }
          catch (UnsupportedFlavorException ex){
              System.out.println(ex);
              ex.printStackTrace();
          }
          catch (IOException ex) {
              System.out.println(ex);
              ex.printStackTrace();
          }
      return clipBoardText;
  }
  </code></pre>
  
  <p>The console output is as follows:</p>
  
  <pre><code>null
  
  Process finished with exit code 0
  </code></pre>
  
  <p>But when I paste the contents of the clipboard into notepad, it has the contents I'm looking for. So it seems to be a problem with how I am retrieving the clipboard contents.</p>