?
Solved

Calling a method

Posted on 2004-03-29
10
Medium Priority
?
292 Views
Last Modified: 2012-05-04
the problem im sure is actually quite simple but i think im appraching it the wrong way.
whenever i compile and run this class it terminated straight away. ie. "Process exit" is displayed.
it creates the object i think cuz there are no erros in my film object code.

basically all i want to know is how do i get the readFilmDetails method to be displayed. Why does my program not ask the user to input the data.

many thanks

pete

class filmTest
{
      //properties
      private String filmName;
      private int filmRating;
      private double filmMinutes;
      private int age;
      
      public static void main(String[] args)
      {
            Film[] film = new Film [5];

      
      }

      public void readFilmDetails()
      {
            System.out.println("Film Name: ");
            filmName = uuInOut.ReadString();
            System.out.println("Enter film rating: ");
            filmRating = uuInOut.ReadInt();
            System.out.println("Enter film minutes");
            filmMinutes = uuInOut.ReadDouble();      
      }

      public void readAge()
      {
            System.out.println("Enter Age: ");
            age = uuInOut.ReadInt();      
      
      }




}
0
Comment
Question by:pete420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 150 total points
ID: 10708716
should be

new filmTest().readFilmDetails();

in main
0
 
LVL 5

Expert Comment

by:twobitadder
ID: 10708741
You don't call the method readFilmDetails.

When your program is first started it executes the main method, you should call readFilmDetails inside here.
eg.

public static void main(String[] args)
     {
          Film[] film = new Film [5];
          readFilmDetails();
     }

0
 
LVL 5

Expert Comment

by:twobitadder
ID: 10708747
public static void main(String[] args)
     {
          Film[] film = new Film [5];
          readFilmDetails();
     }


should be

public static void main(String[] args)
     {
          Film[] film = new Film [5];
          filmTest.readFilmDetails();
     }
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:twobitadder
ID: 10708754
bleh just go with cehj's that's right.
0
 

Author Comment

by:pete420
ID: 10708804
whenever i add in
readFilmDetails();
i get the following error msg.

filmTest.java:14: non-static method readFilmDetails() cannot be referenced from a static context
            filmTest.readFilmDetails();
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10708823
Please read the answers in order pete420. The answer i posted is correct
0
 

Author Comment

by:pete420
ID: 10708847
yes i did see that, no offence was intended,
however i didnt think that was the 'correct' way to do it. i tried it and saw it worked but thought it was a strange way to get it inputed. correct me if im wrong because im hardly experienced in java.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10708873
No it's customary. You can turn your method into a static one and then you *would* be able to call it with

filmTest.readFilmDetails();

but at the moment it's an instance method, not a class one, and therefore requires an instance of class fileTest to be created before it can be called
0
 

Author Comment

by:pete420
ID: 10708891
thanks man, its much appreciated.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10708908
8-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question