Results 1 to 4 of 4
  1. #1
    Manny123 is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Exclamation Method calling help!

    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;
        }
    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"

    What does that mean? :s

  2. #2
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default 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.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Method calling help!

    Moved from Advanced Java.

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default 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)
    Java Code:
        Account acnt1 = new Account();  //Or something simlar that matches a constructor in the Account class
    Then you can act on the Account acnt1 using acnt1.getAccountNumber() etc.

Similar Threads

  1. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 12:40 PM
  2. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 12:03 PM
  3. help w/ method calling
    By blueduiker in forum New To Java
    Replies: 2
    Last Post: 01-12-2010, 08:55 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 06:30 PM
  5. Replies: 29
    Last Post: 09-25-2008, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •