Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    To get rid of the compiler error, delete the line with the error: line 7

  2. #22
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Error ' Cannot find symbol class UserAccount"

    I'd say the OP should study the tutorials some more because s/he obviously doesn't know what s/he is doing; all tips are a waste of effort because the OP wouldn't understand them either ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    Quote Originally Posted by JosAH View Post
    I'd say the OP should study the tutorials some more because s/he obviously doesn't know what s/he is doing; all tips are a waste of effort because the OP wouldn't understand them either ...

    kind regards,

    Jos
    All tips are not a waste of effort. All tips are very welcome and greatly appreciated. Did I misread when I asked my question that this is a "New to Java " forum?

  4. #24
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    Hi

    This is were I am now. It is compiling but it is throwing an error

    Java Code:
    
    import java.util.*;
    
    class accountAR {
    
    
    Account[] Accounts = new Account [10];
    
    
    public int x;
    Scanner input = new Scanner(System.in);
    
    
    
    
    public void mainMenu(){
        int selection;
    
            System.out.print("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("========================");
            System.out.println("| [1]  Check Balance   |");
            System.out.println("| [2]  Withdrawal      |");
            System.out.println("| [3]  Deposit         |");
            System.out.println("| [4]  Exit            |");
            System.out.println("========================");
            System.out.print("Please select your option now: ");
            selection =input.nextInt();
    
    switch (selection){
        case 1:
            viewBalance();
            break;
        case 2:
            withdrawFunds();
            break;
        case 3:
            depositFunds();
            break;
        case 4:
            System.out.println("Thank you for using ATM! \n Goodbye! \n");
    }
    }
    
    
    
    public void setX (int c) {
    	x = c;
    	}
    
    public void viewBalance() {
        int selection1;
        System.out.println("You have selected Balance.\n");
        System.out.println("\t-- Your Current Balance is:$ " + Accounts[x].getbalance());
        System.out.println("Return to main menu? \n [1] for YES \n");
        selection1 =input.nextInt();
    
    switch (selection1){
        case 1:
            mainMenu();
            break;
    }
    
    }
    
    //Method to withdraw money
    public void withdrawFunds() {
        int withdrawSelection;
    
        System.out.println("Amount to withdraw: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        withdrawSelection =input.nextInt();
    
    switch (withdrawSelection){
        case 1:
            Accounts[x].withdraw(20);
            mainMenu();
            break;
        case 2:
            Accounts[x].withdraw(40);
            mainMenu();
            break;
        case 3:
            Accounts[x].withdraw(50);
            mainMenu();
            break;
        case 4:
            Accounts[x].withdraw(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    
    }
    
    // method for choosing how much to deposit
    public void depositFunds(){
        int addSelection;
    
        System.out.println("Amount to deposit: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        addSelection =input.nextInt();
    
        switch (addSelection){
        case 1:
            Accounts[x].deposit(20);
            mainMenu();
            break;
        case 2:
            Accounts[x].deposit(40);
            mainMenu();
            break;
        case 3:
            Accounts[x].deposit(50);
            mainMenu();
            break;
        case 4:
            Accounts[x].deposit(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    }
    
    
    
    public accountAR () {}
    
    // Start main
    
    public static void main (String [] args){
    
    	accountAR a = new accountAR ();
    
    Scanner input1 = new Scanner(System.in);
    // Create 10 account objects
    
    Account[] Account = new Account [10];
    
    
    // loop to create 10 accounts with balance of 50
    
    for (int p = 0; p<10;p++)
     {
    Account [p] = new Account ();
    Account [p].setId (p);
    Account [p].setBalance(50);
    
     }
    
    // Start the welcome message
    
    int p;
    System.out.println("Please enter your ID number\n");
    p =input1.nextInt();
    a.setX(p);
    
    
    
    // If id is incorrect print message or start mainMenu
    if (p > Account.length) {
    	System.out.println ("Please re-enter your ID number\n");
    }
    		else {
    			a.mainMenu(); }
    
    
    
     }
     }

    the error is:

    Exception in thread "main" java.lang.NullPointerException
    at accountAR.depositFunds(accountAR.java:121)
    at accountAR.mainMenu(accountAR.java:37)
    at accountAR.main(accountAR.java:176)
    Last edited by r1b; 01-09-2012 at 10:05 PM.

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    There is a variable on line 121 that has a null value. Find which variable is null and then backtrack to see why that variable does not have a valid value. If you can not see which variable is null, add a println just before line 121 and print the values of all the variables used on 121.

  6. #26
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    Thanks for all your help today Norm.

  7. #27
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Error ' Cannot find symbol class UserAccount"

    Quote Originally Posted by r1b View Post
    All tips are not a waste of effort. All tips are very welcome and greatly appreciated. Did I misread when I asked my question that this is a "New to Java " forum?
    Nope, and my tip has value too: please read those tutorials some more and you'll understand what you're doing.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. "Cannot find symbol" error
    By MBD in forum New To Java
    Replies: 5
    Last Post: 09-27-2011, 02:41 PM
  2. "cannot find symbol" error
    By droidus in forum New To Java
    Replies: 2
    Last Post: 09-07-2011, 07:43 AM
  3. Replies: 5
    Last Post: 04-24-2011, 03:21 PM
  4. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 09:51 PM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM

Posting Permissions

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