• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a Method in one Class from another Class Problem  RSS feed

 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a Java assignment that has me constructing a program to manage a Timetable (school timetable).
In one of the classes I have to create two methods that are identical to two other methods in another class of this program.
Here is the code:


Now I get the error "Cannot make a static reference to the non-static method getDurationString(DateTime) from the type DateTime".

How is it caused? and is it possible to solve the issue WITHOUT making the method in the other class static?

Below is the code of the original methods:


As you can Understand I dont want to be redundant and copy the whole thing into the other class.
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calling the methods? I suspect you are doing it from a main() method that has to be static. Try creating an instance of the class and calling a simple run() math to call everything else out of.

 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No the Methods are called from another class called "Lecture". This class represents lectures for the Timetable.
Here is the code (It is not doen yet):
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you posted to the code that gets the error? What line is it on? Can you post the stack trace?
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I just solved it with hints from stackoverflow.
My mistake was to link directly to DateTime when I had already created an instance to DateTime on top with "start" and "end".
So I just did the following:
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you got a solution, but in the future, BeForthrightWhenCrossPostingToOtherSites (← that's a link). It's okay to post to another site, just tell us.
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that and thanks for the heads up!
I will do so next time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!