Re: Array list problems :s
Which of the lines is 30? From a quick glance, it looks okay to me... Try moving the System.out.println(accountList) to above the accountList.adds. Shouldn't be a problem though...
Re: Array list problems :s
Which of the lines is 30? From a quick glance, it looks okay to me... Try moving the System.out.println(accountList) to above the accountList.adds. Shouldn't be a problem though...
Although the line "public class Accountpublic class Account" looks odd to me. How did that even compile?
Re: Array list problems :s
line 30 is simply me using the } symbol to close my other method and the "public class Accountpublic class Account" was jus a copy and paste mistake made by me.
Re: Array list problems :s
Code:
import java.util.ArrayList;
/**
* Write a description of class Account here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Account
{
// instance variables - replace the example below with your own
private String accountName;
private Integer accountNumber;
private Integer sortCode;
private Bank bank;
private ArrayList<String> accountList;
/**
* Constructor for objects of class Account
*/
public Account(String accountName, Integer accountNumber, Integer sortCode, Bank bankName)
{
// initialise instance variables
this.accountName = accountName;
this.accountNumber = accountNumber;
this.sortCode = sortCode;
bank = bankName;
accountList = new ArrayList<String>();
}
public void viewAvailableAccounts(){
accountList = new ArrayList<String>();
//Account accounts = new Account();
accountList.add("Savings Account");
accountList.add("Current Account");
System.out.println(accountList);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
}
this is the original code
Re: Array list problems :s
Well, there's definitely something missing in the example... The exception says it should be in the accountTypes method in the Account class.
Re: Array list problems :s
Could you post your entire stacktrace? It would look something like this:
Code:
Exception in thread "main" java.lang.NullPointerException
at test.splittest(test.java:19)
at test.<init>(test.java:14)
at test.main(test.java:9)
Re: Array list problems :s
stacktrace? Sorry i'm kinda new what is a stacktrace?
Re: Array list problems :s
Basically, the whole text you get when you get an exception like that. It should look a little like what I posted just above.
Re: Array list problems :s
Don't worry, its working now. Cheers