Results 1 to 4 of 4
Thread: Method calling help!
- 10-27-2012, 03:51 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Method calling help!
I'm trying to do a check so that if the account number number and sort code (which they entered in the Account class) doesn't match what they have entered in the transaction class, it will display an error message however, i get an error on the line which is in bold stating (line 13) "non-static method getAccountNumber() cannot be referenced from a static context"Java Code:public class Transaction { // instance variables - replace the example below with your own private Integer amount; private Integer balance; /** * Constructor for objects of class Transaction */ public Transaction(Integer AccountNumber, Integer SortCode) { // initialise instance variables [B] if((AccountNumber != Account.getAccountNumber())&&(SortCode != Account.getSortCode())){[/B] System.out.print("Incorrect account number or sort code"); } balance = null; amount = null; }
What does that mean? :s
- 10-27-2012, 07:26 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 34
- Rep Power
- 0
Re: Method calling help!
you are calling the method getAccountNumber using Account.getAccountNumber,
that's not cool, unless that method is declared static in the Account class, which mean that it is a single method shared by all
the instances.. i don't think that's what you meant.
- 10-27-2012, 09:23 PM #3
Re: Method calling help!
Moved from Advanced Java.
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-27-2012, 11:18 PM #4
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
Re: Method calling help!
You must first Instantiate an Account object. (Unless as Arieltal suggested the methods are static... which is really not what the Account class seems to be built for)
Then you can act on the Account acnt1 using acnt1.getAccountNumber() etc.Java Code:Account acnt1 = new Account(); //Or something simlar that matches a constructor in the Account class
Similar Threads
-
Thread problem, calling method in run method
By majk in forum Threads and SynchronizationReplies: 4Last Post: 09-27-2010, 11:40 AM -
Calling The main method from another method
By SwissR in forum New To JavaReplies: 3Last Post: 07-27-2010, 11:03 AM -
help w/ method calling
By blueduiker in forum New To JavaReplies: 2Last Post: 01-12-2010, 07:55 AM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks