Could not find the main class: javaapplication3.Main

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trdmrk
    New Member
    • Jun 2010
    • 1

    Could not find the main class: javaapplication3.Main

    Hello,

    Ive found this site very helpful in the past, so i thought i may ask for help.

    I am developing an application for a school project. I am in the middle of it, I get the error: java.lang.Excep tionInInitializ erError
    Caused by: java.lang.NullP ointerException
    at sun.misc.Floati ngDecimal.readJ avaFormatString (FloatingDecima l.java:991)
    at java.lang.Doubl e.parseDouble(D ouble.java:510)
    at javaapplication 3.Main.<clinit> (Main.java:18)
    Could not find the main class: javaapplication 3.Main. Program will exit.
    Exception in thread "main" Java Result: 1

    It cannot find the main class, ive tried everything i can think of and a fair bit of looking around on the net for solutions but to no avail.

    its pretty urgent as i cant proceed because i cant test, any help would be much appreciated!

    Code:
    package ChadstoneCommunityBank;
    
    import javax.swing.*;
    import java.util.ArrayList;
    
    public class main {
    
            private static ArrayList<ChequeAccount> ChequeAccount = new ArrayList<ChequeAccount>();
            private static  ArrayList<InvestmentAccount> InvestmentAccount = new ArrayList<InvestmentAccount>();
            private static ArrayList<PassbookAccount> PassbookAccount = new ArrayList<PassbookAccount>();
            private static String name, address, balance, overdraft;
            private static double Balance = Double.parseDouble(balance);
            private static double Overdraft = Double.parseDouble(overdraft);
    
       public static void main(String[] args)
    
           int choice = mainMenu(); //Menu System
    		while(choice != 8)
    		{
    			switch(choice)
    			{
    				case 1:
    					createAccount();
    					break;
    				case 2:
    					//addStudent();
    					break;
    				case 3:
    					//printDetails();
    					break;
                    case 4:
    					//createSubject();
    					break;
    				case 5:
    					//addInterest();
    					break;
    				case 6:
    					//printDetails();
    					break;
                    case 7:
    					//createSubject();
    					break;
    				default:
    					JOptionPane.showMessageDialog(null, "Not a valid option, select again");
    
    			}
    			choice = mainMenu();
    		}
    		System.exit(0);
    	}
    //-----------------------------------------------------------------------------------------------------------------------------------------------
    	public static int mainMenu()
    	{
    		String displayMenu;
    		displayMenu = JOptionPane.showInputDialog(null, "1.   Add New Account\n2.   Withdraw\n3.   Deposit\n4.   Update Overdraft\n5.   Add Interest\n6.   Print Balance\n7.   Print All\n8.   Quit\n\nEnter Your Option (Enter 8 to quit):");
    		int temp = validateMenuInput(displayMenu);
    		return temp;
    	}
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
                public static int validateMenuInput(String aString)
    	{
    		if (aString.length()<1 || aString==null)//User didnt Enter a selection
    		{
    			JOptionPane.showMessageDialog(null,"Not A Valid Option, Please Input a Number!");
    			return 0;
    		}
    		else
    			if(!Character.isDigit(aString.charAt(0))||(aString.length()>1)) //User Entered a Character
    			{
    				JOptionPane.showMessageDialog(null,"Not An Valid Option, Please Input a Number!");
    				return 0;
    			}
    			else
    				return (Integer.parseInt(aString));
    
    	}
    
    //-------------------------------------------------------------------------------------------------------------------------------------------------------
    
           //  public static double addInterest(double rate)
           //  {
             //    balance = BankAccountgetBalance();
             //    balance = balance * (1 + (rate/100.0));
                 
             //    return balance;
            // }
     
    
    //-------------------------------------------------------------------------------------------------------------------------------------------------------
    //Create Account Menu
            public static void createAccount()
            {
                   int choice = addAccount(); //Menu System
    		while(choice != 3)
    		{
    			switch(choice)
    			{
    				case 1:
    					createChequeAccount();
    					break;
    				case 2:
    					createPassbookAccount();
    					break;
    				case 3:
    					createInvestmentAccount();
    					break;
                                 
    				default:
    					JOptionPane.showMessageDialog(null, "Not a valid account type, Please try again");
    
    			}
    			choice = addAccount();
    		}
    
            }
    
           public static int addAccount()
    	{
    		String displayMenu;
    		displayMenu = JOptionPane.showInputDialog(null, "1.   Cheque Account\n2.   Passbook Account\n3.   Investment Account");
    		int temp = validateMenuInput(displayMenu);
    		return temp;
    	}
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
    //Create Account Methods
           public static void createChequeAccount()
           {
                    //Ask for New account information
                    name = JOptionPane.showInputDialog(null, "Enter Account Holders Name");
                    address = JOptionPane.showInputDialog(null, "Enter Account Holders Address");
                    balance = JOptionPane.showInputDialog(null, "Enter Opening Balance");
                    overdraft = JOptionPane.showInputDialog(null, "Enter Overdraft Amount");
    
                    //Add account to Array
    			ChequeAccount ca = new ChequeAccount(name, address, Balance, Overdraft);
    			ChequeAccount.add(ca);
                    //Display New account information
                            int size = ChequeAccount.size()-1;
                            JOptionPane.showMessageDialog(null, "Account information" + ChequeAccount.get(size));
           }
    
           public static void createPassbookAccount()
           {
                    //Ask for New account information
                    name = JOptionPane.showInputDialog(null, "Enter Account Holders Name");
                    address = JOptionPane.showInputDialog(null, "Enter Account Holders Address");
                    balance = JOptionPane.showInputDialog(null, "Enter Opening Balance");
    
                    //Add account to Array
    			PassbookAccount pa = new PassbookAccount(name, address, Balance);
    			PassbookAccount.add(pa);
           }
    
           public static void createInvestmentAccount()
           {
                    //Ask for New account information
                    name = JOptionPane.showInputDialog(null, "Enter Account Holders Name");
                    address = JOptionPane.showInputDialog(null, "Enter Account Holders Address");
                    balance = JOptionPane.showInputDialog(null, "Enter Opening Balance");
    
                    //Add account to Array
    			InvestmentAccount ia = new InvestmentAccount(name, address, Balance);
    			InvestmentAccount.add(ia);
           }
    
    //---------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    }
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    The initialization of your variables are wrong:

    private static String name, address, balance, overdraft;
    private static double Balance = Double.parseDou ble(balance);
    private static double Overdraft = Double.parseDou ble(overdraft);

    balance and overdraft have not been set, so they will throw errors when the program is run.

    Suggestion:
    declare the double s but do not set them yet:
    private static double Balance,Overdra ft;

    whenever you change balance and overdraft, set Balance and Overdraft respectively.

    Comment

    Working...