Solved

Calling a method

Posted on 2004-03-29
10
246 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
  • 4
  • 3
  • 3
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
Comment Utility
should be

new filmTest().readFilmDetails();

in main
0
 
LVL 5

Expert Comment

by:twobitadder
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:twobitadder
Comment Utility
bleh just go with cehj's that's right.
0
 

Author Comment

by:pete420
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 86

Expert Comment

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

Author Comment

by:pete420
Comment Utility
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
Comment Utility
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
Comment Utility
thanks man, its much appreciated.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
HashMap Vs TreeMap 12 48
thymeleaf natural templating vs JSP 2 23
JList custom Cell Renderer refresh 15 39
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now