Solved

Calling a method

Posted on 2004-03-29
10
260 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

920 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

14 Experts available now in Live!

Get 1:1 Help Now