Errors when appending to JTextArea

When I run my applet using the following code, I get all kinds of errors in the compiler (listed after the code). I'm not able to determine what is causing the errors, please help.....

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import java.text.DecimalFormat;

publicclass MtgCalculatorextends JFrameimplements ActionListener

{

//declarations for GUI

privatestaticdouble mortAmt=0.0;//double variable for loan amount

privatestaticdouble monthlyPay=0.0;//double variable for monthly payment

privatestaticdouble InterestRate=0.0;//double variable for interest rate

privatestaticint termLength=0;//integer variable for duration (term)

privateboolean clearText=true;//clear text flag for clearing text fields

privateint PaymentNumber=0;

privatedouble presMonthInt = 0.0;

privatedouble principlePaid = 0.0;

privatedouble monthEndPrinciple = 0.0;

DecimalFormat moneyFormat=new DecimalFormat("$###,###.00");//format pattern for currency values

DecimalFormat intRateFormat=new DecimalFormat("##.###%");//format pattern for Interest Rate (add % symbol)

DecimalFormat yearsFormat=new DecimalFormat("## years");//format pattern for duration (term)

JComboBox termRateText =new JComboBox(new String[]{"","7 years @ 5.35%","15 years @ 5.5%","30 years @ 5.75%"});

JTextField principleValueText =new JTextField();

JTextField pmtText =new JTextField(10);

JTextArea displayAmortInfo;

AbstractButton calcButton =new JButton(" Calculate ");

AbstractButton clrButton =new JButton("Clear Fields");

publicvoid buildGUI()

{

JFrame frame =new JFrame();

frame.setTitle("Mortgage Payment Calculator Version 5.0");

frame.getContentPane().add(getTopPanel(),BorderLayout.NORTH);

frame.getContentPane().add(getBottomPanel(),BorderLayout.CENTER);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setResizable(false);

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

private JPanel getTopPanel()

{

JPanel panel =new JPanel(new BorderLayout());

JPanel topRow =new JPanel(new GridLayout(1,6));

topRow.add(new JLabel("Principle Value: ",JLabel.RIGHT));

topRow.add(principleValueText);

topRow.add(new JLabel("Loan Terms: ",JLabel.RIGHT));

topRow.add(termRateText);

JPanel bottomRow =new JPanel(new GridLayout(1,2));

JPanel leftSide =new JPanel();

leftSide.add(calcButton);

leftSide.add(clrButton);

JPanel rightSide =new JPanel();

rightSide.add(new JLabel("Monthly Payment: ",JLabel.RIGHT));

rightSide.add(pmtText);

bottomRow.add(leftSide);

bottomRow.add(rightSide);

calcButton.addActionListener(this);

clrButton.addActionListener(this);

panel.add(topRow,BorderLayout.NORTH);

panel.add(bottomRow,BorderLayout.SOUTH);

return panel;

}

private JPanel getBottomPanel()

{

JPanel panel =new JPanel(new BorderLayout());

JPanel topRow =new JPanel(new GridLayout(1,1));

topRow.add(new JLabel("Payment #", JLabel.LEFT));

topRow.add(new JLabel("Loan Balance", JLabel.LEFT));

topRow.add(new JLabel("Interest Paid", JLabel.LEFT));

JPanel bottomRow =new JPanel(new GridLayout(1,1));

JTextArea displayAmortInfo =new JTextArea(25, 50);

JScrollPane sp =new JScrollPane(displayAmortInfo);

panel.add(sp);

panel.add(topRow,BorderLayout.NORTH);

panel.add(bottomRow,BorderLayout.SOUTH);

return panel;

}

publicvoid actionPerformed(ActionEvent event)//activating the action event so the user's input is taken

{

//checking for user button clicks

if(event.getSource() == calcButton)//user clicks the Calculate button

{

clearText=false;//set clear text flag to false

int menuNum = termRateText.getSelectedIndex();

switch(menuNum){

case 0:

InterestRate=0.0;

termLength=0;

break;

case 1:

InterestRate=5.35;

termLength=7;

break;

case 2:

InterestRate=5.50;

termLength=15;

break;

case 3:

InterestRate=5.75;

termLength=30;

break;

}

mortAmt=new Double(principleValueText.getText().trim()).doubleValue();//parse LoanAmt to double

//calculate Monthly Payment amount for mortgage and display in Monthly Payment field

monthlyPay=(mortAmt*(InterestRate/(12*100)))/(1-Math.pow(1+(InterestRate/(12*100)),-(termLength*12)));//calculate

principleValueText.setText(moneyFormat.format(mortAmt));//set format for loan amount field

pmtText.setText(moneyFormat.format(monthlyPay));

while(PaymentNumber < termLength*12)//Starts the loop for displaying the table, loop

{//continues until all payments have been displayed

PaymentNumber++;

presMonthInt = mortAmt * (InterestRate/12);//this calculates the monthly interest paid

principlePaid = monthlyPay - presMonthInt;//this calculates the monthly principle paid

monthEndPrinciple = mortAmt - principlePaid;//this calculates what the principle after the payment

//Display the total loan information in text scroll area

displayAmortInfo.append(PaymentNumber +"\t"

+ moneyFormat.format(monthEndPrinciple) +"\t\t"

+ moneyFormat.format(presMonthInt)+"\n");

displayAmortInfo.setCaretPosition(0);

}//end while loop for Amortization table

}//end if for Calc button

elseif(event.getSource() == clrButton)//user clicks the Reset button

{

clearText=true;//set clear text flag to true for new calculation

principleValueText.setText("");//clears the mortgage amount field

pmtText.setText("");//clears the mortgage payment field

termRateText.setSelectedIndex(0);//clears the interest rate field

displayAmortInfo.setText("");

principleValueText.requestFocus();//return cursor to mortgage amount field

}//end else if for Reset button

}//end check for button clicks

publicstaticvoid main(String[] args)

{

SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

new MtgCalculator().buildGUI();}});

}

}

Here's the errors I'm getting:

java.lang.NullPointerException

at MtgCalculator.actionPerformed(MtgCalculator.java:132)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

[13931 byte] By [Confusionousa] at [2007-11-26 13:56:52]
# 1
The error seems fairly clear:Line 132 of MtgCalculator is throwing a null pointer exception.More than likely you are trying to access something that is null.
zadoka at 2007-7-8 1:36:38 > top of Java-index,Desktop,Core GUI APIs...
# 2

you have this field

JTextArea displayAmortInfo;

in getBottomPanel() you have this

JTextArea displayAmortInfo = new JTextArea(25, 50);

the displayAmortInfo you have created is local to getBottomPanel(),

the other one (the field), which is referenced in actionPerformed(), is still null

to fix, change

JTextArea displayAmortInfo = new JTextArea(25, 50);

to

displayAmortInfo = new JTextArea(25, 50);

Michael_Dunna at 2007-7-8 1:36:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks for the quick replies folks.......Michael, that fixed the problem in a pinch!!!!!Now I just need to figure out why the calculations in the loop aren't working the right way......
Confusionousa at 2007-7-8 1:36:39 > top of Java-index,Desktop,Core GUI APIs...