I keep getting this error on my else. Anyone have any ideas? I don't quit understand this error as the the if works just fine, and it is same thing. it just sends it to a different array.
catch ( NoSuchElementException e ) //Error
{
System.err.println( "Invalid input62" );
System.exit( 1 );
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.FormatterClosedException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
//Declarations
Account[] Account = new Account[8];
Checking[] Checking = new Checking[4];
Savings[] Savings = new Savings[4];
int ACount = 0;
int CCount = 0;
int SCount = 0;
Scanner inAccount = null;
Scanner inTrans = null;
String AccountType = null;
int AccountNumber = 0;
double AccountBalance = 0;
String Date;
int sAmount;
double Action;
try //Open text file
{
inAccount = new Scanner( new File( "Account.Txt" ) );
}
catch ( FileNotFoundException e ) //Error e
{
System.err.println( "Error: file not found" );
System.exit( 1 );
}
try
{
inAccount.useDelimiter("[,\\r\\n]+"); //Delimiter
while( inAccount.hasNext() ) //Reads the file
{
AccountType = inAccount.next();
AccountNumber = inAccount.nextInt();
AccountBalance = inAccount.nextDouble();
Account[ACount] = new Account( AccountType, AccountNumber, AccountBalance);
ACount++; //Loops
}
}
catch ( FormatterClosedException e ) //Error
{
System.err.println( "Error writing to file" );
System.exit( 1 );
}
catch ( NoSuchElementException e ) //Error
{
System.err.println( "Invalid input" );
System.exit( 1 );
}
if(AccountType.equals("C")){
try //Open text file
{
inTrans = new Scanner( new File( "Trans.Txt" ) );
}
catch ( FileNotFoundException e ) //Error e
{
System.err.println( "Error: file not found" );
System.exit( 1 );
}
try
{
inAccount.useDelimiter("[,\\r\\n]+"); //Delimiter
while( inTrans.hasNext() ) //Reads the file
AccountNumber=inTrans.nextInt();
Date = inTrans.next();
sAmount = inTrans.nextInt();
Action = inTrans.nextDouble();
Checking[CCount] = new Checking (AccountType,AccountNumber,AccountBalance,
Date, sAmount, Action);
CCount++;
}
catch ( FormatterClosedException e ) //Error
{
System.err.println( "Error writing to file" );
System.exit( 1 );
}
catch ( NoSuchElementException e ) //Error
{
System.err.println( "Invalid input" );
System.exit( 1 );
}
}
else{
try //Open text file
{
inTrans = new Scanner( new File( "Trans.Txt" ) );
}
catch ( FileNotFoundException e ) //Error e
{
System.err.println( "Error: file not found" );
System.exit( 1 );
}
try
{
inAccount.useDelimiter("[,\\r\\n]+"); //Delimiter
while( inTrans.hasNext() ) //Reads the file
AccountNumber=inTrans.nextInt();
Date = inTrans.next();
sAmount = inTrans.nextInt();
Action = inTrans.nextDouble();
Savings[SCount] = new Savings(AccountType,AccountNumber,AccountBalance,
Date, sAmount, Action);
SCount++;
}
catch ( FormatterClosedException e ) //Error
{
System.err.println( "Error writing to file" );
System.exit( 1 );
}
catch ( NoSuchElementException e ) //Error
{
System.err.println( "Invalid input62" );
System.exit( 1 );
}
if ( inAccount != null )
inAccount.close();
if ( inAccount != null )
inAccount.close();
//************Formatting loop**********************
for( int i = 0; i < Account.length; i++ ){
System.out.println();
System.out.print("Account:");
System.out.print(Account[i].getAccountNumber());
System.out.println();
System.out.print("Type:");
System.out.print(Account[i].getAccountType());
System.out.println();
System.out.print("Balance:");
System.out.print(Account[i].getAccountBalance());
System.out.println();
}
}
}
}