Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why doesn't my period class compile

 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me with Periods in Java
 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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...
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remove the earlier .java and .class files for Period?
 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Did you remove the earlier .java and .class files for Period?

I removed .class file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic