title: Cannot find symbol for method format(DateTimeFormatter)?
body: <p>I'm having a problem and I absolutely can't wrap my head around it. I am inexperienced in Java (or any language, for that matter), so excuse me if this is a stupid question.</p>
  <p>From what I can tell, the format() method from java.time.format.DateTimeFormatter is not working how I thought it did. I am consistently getting the following error message (CLI):</p>
  <pre><code>Watch.java:609: error: cannot find symbol
                  String dateTimeDisplay = dateTime.format(dateTimeFormat);
                                                   ^
    symbol:   method format(DateTimeFormatter)
    location: variable dateTime of type Object
  1 error
  </code></pre>
  <p>And here are the bits of code I think are relevant:</p>
  <pre><code>import java.time.ZonedDateTime;
  import java.time.ZoneId;
  import java.time.format.DateTimeFormatter;
  
  public class Watch {
      
      protected int hour, hourTens, hourOnes, minute, minuteTens, minuteOnes, amPM;
      
      public void watchMethod(String userInput) { 
          
          Object dateTime; // Create reference to object called dateTime
      
          switch (userInput) {
              case &quot;1&quot;:
              ZonedDateTime dateTimeHere = ZonedDateTime.now();
              hour = dateTimeHere.getHour();
              minute = dateTimeHere.getMinute();
              // amPM is used exclusively to display AM/PM or a heart (see lines 580 to 567).
              amPM = dateTimeHere.getHour();
              dateTime = dateTimeHere;
              break;
              
              case &quot;2&quot;:
              ZonedDateTime dateTimeThere = ZonedDateTime.now(ZoneId.of(&quot;Europe/Paris&quot;));
              hour = dateTimeThere.getHour();
              minute = dateTimeThere.getMinute();
              // amPM is used exclusively to display AM/PM or a heart (see lines 560 to 567).
              amPM = dateTimeThere.getHour();
              dateTime = dateTimeThere;
              break; 
              
              case &quot;3&quot;:
              hour = -1;
              minute = -1;
              break;
          }
  
          // There is some code that prints things to console depending on the hour, minute, and amPM variables.
          // I don't think this is relevant, but that's what's here.
  
          // The following code prints out the actual date and time from a ZonedDateTime object.
          DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern(&quot;hh:mm a 'on' EEEE, MMMM dd, yyyy&quot;);
          String dateTimeDisplay = dateTime.format(dateTimeFormat); // ERROR
          System.out.print(&quot;\nIt is currently &quot; + dateTimeDisplay + &quot;\n&quot;);
      }
  }
  </code></pre>
  <p>This is all one class.</p>
  <p>I have checked that my imports are correct and that there are no misspellings anywhere! This is what other questions related to my problem have led me to believe was the issue, but it doesn't seem to be the case.</p>
  <p>I'm also not very familiar with using <code>Object</code> as a reference type, so if that could be what's causing the problem, I'm not surprised. It's all I could figure out to break <code>dateTimeHere</code>/<code>dateTimeThere</code> out of the switch block.</p>
  <p>Anyway, I'd greatly appreciate any help I receive.</p>
  <p>QUICK EDIT: I also figured that if there were no suitable <code>dateTime</code> object (i.e. case &quot;3&quot;), this would also cause an error. I briefly added an <code>if/else</code> statement to remedy this, with some code in case &quot;3&quot; indicating that dateTime was null, but this did absolutely nothing. Let me know if I should re-add this, though.</p>
  <p>EDIT: Thanks to a comment from @MarsAtomic, I see that this post could have used another read-through. My problem is that at the end of my code, I want to print out the ZonedDateTime data the switch statement retrieved, whether that is from the user's computer location or &quot;Paris/Europe&quot;. Eventually, that &quot;Paris/Europe&quot; string will (ideally) have some user input from a subclass (as is the case with userInput, but that particular string was just for choosing one of the 3 cases already shown).</p>