• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why doesn't my period class compile

 
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me with Periods in Java
 
yogesh doshi
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to compile  code on Java 8 version still giving compiled time error
Period period = Period.ofMonths(1); // create a period
                     ^
 symbol:   method ofMonths(int)
 location: class Period
Period_demo.java:16: error: no suitable method found for plus(Period)
upTo = upTo.plus(period); // adds the period
          ^
   method Temporal.plus(TemporalAmount) is not applicable
     (argument mismatch; Period cannot be converted to TemporalAmount)
   method ChronoLocalDate.plus(TemporalAmount) is not applicable
     (argument mismatch; Period cannot be converted to TemporalAmount)
   method LocalDate.plus(TemporalAmount) is not applicable
     (argument mismatch; Period cannot be converted to TemporalAmount)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to ge
full output


 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yogesh,
This is happening because you named your class the same as one in Java. So from the main method's point of view, the Period class refers to the one you typed in rather than the one in java.time.

The best way to resolve this is name your class something different. If you really want to use the same name, you'll need to fully qualify the type so Java knows you mean the built in Period class:

 
yogesh doshi
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...
But still after changing the name it didnt work. It is throwing the same error can you please help me ....The updated code is as below...
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you remove the earlier .java and .class files for Period?
 
yogesh doshi
Ranch Hand
Posts: 49
Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks @Jeanne Boyarsky...
Finally code work....
I changed the file name and class name but i didn't deleted the previous Period.class file. You are amazing.. Thanks once again
 
yogesh doshi
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Did you remove the earlier .java and .class files for Period?


I removed .class file
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic