Results 1 to 5 of 5
Thread: get accountNumber problem
- 09-21-2012, 06:59 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 13
- Rep Power
- 0
get accountNumber problem
I have five classes: Account (abstract), SavingAccount, CreditAccount, GUI and Logic. My problem is the showSelecteAccountNumber method, and the problem is in this line: if(selectedAccountNr==konto.getAccountNumber()){
selectedAccountNr is no problem. It comes from the accountNrField. It is konto.getAccountNumber() which is the problem. Compilation is no problem but it gives the following error message
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GUI.showSelectedAccount(GUI.java:556)
at GUI.access$16(GUI.java:546)
at GUI$ShowSelectedAccountListener.actionPerformed(GU I.java:173)
I think I don´t communicate correct between the classes, but I really don´t know how to get the accountNumber from the account list. Can someone help me to get it work??
Logic:
GUI:Java Code:public class Logic{ private ArrayList<Customer> customers = new ArrayList<Customer>(); private ArrayList<Account> accounts = new ArrayList<Account>(); public Logic() { customers = new ArrayList<Customer>(); accounts = new ArrayList<Account>(); } public void addCustomer(String fName, String eName, String pNumber){ customers.add(new Customer(fName, eName, pNumber)); } public void addSavingAccount(String pNumber) { accounts.add(new SavingAccounts(pNumber)); } public void addCreditAccount(String pNumber) { accounts.add(new CreditAccounts(pNumber)); } // Accessors public ArrayList<Customer> getAllCustomers(){ return customers; } public ArrayList<Account> getAllAccounts(int acountNumber, double StartingBalance, String kontoTyp, String PNumber){ return accounts; } public String getFirstNameForCustomerAt(int position){ return (customers.get(position)).getFirstName(); } public String getSecondNameForCustomerAt(int position){ return (customers.get(position)).getSecondName(); } public String getPNumberForCustomerAt(int position){ return (customers.get(position)).getPNumber(); } public int getAccountNumberForCustomerAt(int position){ return (accounts.get(position)).getAccountNumber(); } public ArrayList<Account> getAccounts() { return accounts; } ....... }
Java Code:public class GUI extends JFrame { private Customer kund; private Logic logic; private Account konto; .... private JTextField firstNameField; private JTextField secondNameField; private JTextField pNumberField; private JTextField accountNrField; .... private ArrayList<Customer> customers; //JLists kunder=new JList(new DefaultListModel()); konton = new JList<Object>(); // Listerners // Menu .... private void addSAccount(int accountNumber, double balance, String kontoTyp, String valdKundPNr){ logic.addSavingAccount(selectedKundPNr); konton.setListData(logic.getAllAccounts(accountNumber, startingBalance, kontoTyp, valdKundPNr).toArray()); clear(); } private void addCAccount(int accountNumber, double balance, String kontoTyp, String valdKundNr){ logic.addCreditAccount(selectedKundPNr); konton.setListData(logic.getAllAccounts(accountNumber, startingBalance, kontoTyp, valdKundPNr).toArray()); clear(); } private int showSelectedAccount(String selectedCustomerNr){ int position = kunder.getSelectedIndex(); displayJTextArea.setText(""); if(position > -1){ firstNameField.setText(logic.getFirstNameForCustomerAt(position)); secondNameField.setText(logic.getSecondNameForCustomerAt(position)); selectedAccountNr= Integer.parseInt(accountNrField.getText()); for(int j=0; j< konton.getModel().getSize(); j++){ if(selectedAccountNr==konto.getAccountNumber()){ Object item = konton.getModel().getElementAt(j); displayJTextArea.append("\nKonto med " + item + " \n"); } } } else { JOptionPane.showMessageDialog(null, "You have to select an account in the list!"); } clear(); return selectedAccountNr; }
- 09-21-2012, 11:20 PM #2
Re: get accountNumber problem
Have you found the variable with the null value on line 556? You need to find which variable has the null value and then backtrack in the code to find out why that variable does not have a valid non-null value.Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GUI.showSelectedAccount(GUI.java:556)
Does the variable: konto have a valid value when line 556 is executed?problem is in this line: if(selectedAccountNr==konto.getAccountNumber()){Last edited by Norm; 09-21-2012 at 11:22 PM.
If you don't understand my response, don't ignore it, ask a question.
- 09-22-2012, 05:16 AM #3
Member
- Join Date
- Jun 2012
- Posts
- 13
- Rep Power
- 0
Re: get accountNumber problem
I think the problem is private Account konto; in the Account class.
I don´t know how to get the right accountNumber from the arrayList accounts.
- 09-22-2012, 01:54 PM #4
Re: get accountNumber problem
Does the variable: konto have a value when line 556 is executed?
Where is it assigned a value?If you don't understand my response, don't ignore it, ask a question.
- 09-22-2012, 02:05 PM #5
Member
- Join Date
- Jul 2012
- Posts
- 37
- Rep Power
- 0
Similar Threads
-
Problem to get accountNumber
By ostkanten in forum New To JavaReplies: 3Last Post: 09-19-2012, 01:44 PM -
Problems getting an unique accountNumber
By ostkanten in forum New To JavaReplies: 11Last Post: 08-14-2012, 12:08 PM -
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 03:43 AM -
Can anyone see the problem with my code? problem understanding switch (newbish)
By keith in forum New To JavaReplies: 9Last Post: 09-21-2010, 04:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks