hello friends,I made an applet to calculate sales tax but i am having a problem in executing it.It is giving error on execution.
and the error it is giving is,

cant create:java.lang.reflect.InvocationTargetException

following is the piece of code of applet.
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class Tax extends JApplet implements ActionListener
{

JTextField articleText,priceText,quantityText,rateText,paymentText;
JButton doIt;
String article;
double price;
double quantity;
double intRate;
NumberFormat nf;
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
makeGUI();
}
});
}catch(Exception exc)
{
System.out.println("cant create:"+exc);
}
}
private void makeGUI()
{
GridBagLayout gbag=new GridBagLayout();
setLayout(gbag);
GridBagConstraints gbc=new GridBagConstraints();
JLabel heading=new JLabel("compute sales tax for an article");
JLabel articleLab=new JLabel("Name Of The Article");
JLabel quantityLab=new JLabel("Quantity");
JLabel priceLab=new JLabel("Price");
JLabel rateLab=new JLabel("Tax Rate");
JLabel paymentLab=new JLabel("Payments");
articleText=new JTextField(10);
quantityText=new JTextField(10);

priceText=new JTextField(10);

rateText=new JTextField(10);
paymentText.setEditable(false);
doIt=new JButton("compute");
gbc.weighty=1.0;
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbc.anchor=GridBagConstraints.NORTH;
gbag.setConstraints(heading,gbc);
gbc.anchor=GridBagConstraints.EAST;

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(articleLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(articleText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(rateLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(rateText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(priceLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(priceText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(quantityLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(quantityText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(paymentLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(paymentText,gbc);

gbc.anchor=GridBagConstraints.CENTER;
gbag.setConstraints(doIt,gbc);
add(heading);
add(articleLab);
add(articleText);
add(priceLab);
add(priceText);
add(rateLab);
add(rateText);
add(quantityLab);
add(quantityText);

add(paymentLab);
add(paymentText);
add(doIt);
articleText.addActionListener(this);
priceText.addActionListener(this);
rateText.addActionListener(this);
quantityText.addActionListener(this);
doIt.addActionListener(this);
nf=NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
}
public void actionPerformed(ActionEvent ae)
{
double result=0.0;

String articleStr=articleText.getText();
String priceStr=priceText.getText();
String rateStr=rateText.getText();
String quantityStr=quantityText.getText();

try{
if(priceStr.length()!=0&&rateStr.length()!=0&&quantityStr.length()!=0)
{


price=Double.parseDouble(priceStr);
intRate=Double.parseDouble(rateStr);
quantity=Double.parseDouble(quantityStr);
result=compute();
paymentText.setText(nf.format(result));
}
showStatus(" ");
}catch(NumberFormatException exc)
{
showStatus("invalid input");
paymentText.setText(" ");
}}
double compute()
{
double tax;
double pay;
double e;
double b;
tax=(quantity*price*intRate)/100;
pay=(quantity*price)+tax;

return pay;
}
}

plz help me i will be really thankful to you guys.

This is your post # 12 and yet your are not aware of how you post source code?

Please read this before you post any thing.

This is your post # 12 and yet your are not aware of how you post source code?

Please read this before you post any thing.

ok i will do take care of it in future but what about its solution if you can tell me i will be really thankful to you.

You haven't instantiated paymentText. See line no: 48

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class Tax extends JApplet implements ActionListener 
{

JTextField articleText,priceText,quantityText,rateText,paymentText;
JButton doIt;
String article;
double price;
double quantity;
double intRate;
NumberFormat nf;
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
makeGUI();
}
});
}catch(Exception exc)
{
System.out.println("cant create:"+exc);
}
}
private void makeGUI()
{
GridBagLayout gbag=new GridBagLayout();
setLayout(gbag);
GridBagConstraints gbc=new GridBagConstraints();
JLabel heading=new JLabel("compute sales tax for an article");
JLabel articleLab=new JLabel("Name Of The Article");
JLabel quantityLab=new JLabel("Quantity");
JLabel priceLab=new JLabel("Price");
JLabel rateLab=new JLabel("Tax Rate");
JLabel paymentLab=new JLabel("Payments");
articleText=new JTextField(10);
quantityText=new JTextField(10);

priceText=new JTextField(10);
rateText=new JTextField(10);
// ----
paymentText=new JTextField(10);
//---
paymentText.setEditable(false);
doIt=new JButton("compute");
gbc.weighty=1.0;
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbc.anchor=GridBagConstraints.NORTH;
gbag.setConstraints(heading,gbc);
gbc.anchor=GridBagConstraints.EAST;

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(articleLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(articleText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(rateLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(rateText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(priceLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(priceText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(quantityLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(quantityText,gbc);

gbc.gridwidth=GridBagConstraints.RELATIVE;
gbag.setConstraints(paymentLab,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbag.setConstraints(paymentText,gbc);

gbc.anchor=GridBagConstraints.CENTER;
gbag.setConstraints(doIt,gbc);
add(heading);
add(articleLab);
add(articleText);
add(priceLab);
add(priceText);
add(rateLab);
add(rateText);
add(quantityLab);
add(quantityText);

add(paymentLab);
add(paymentText);
add(doIt);
articleText.addActionListener(this);
priceText.addActionListener(this);
rateText.addActionListener(this);
quantityText.addActionListener(this);
doIt.addActionListener(this);
nf=NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
}
public void actionPerformed(ActionEvent ae)
{
double result=0.0;

String articleStr=articleText.getText();
String priceStr=priceText.getText();
String rateStr=rateText.getText();
String quantityStr=quantityText.getText();

try{
if(priceStr.length()!=0&&rateStr.length()!=0&&quantityStr.length()!=0)
{


price=Double.parseDouble(priceStr);
intRate=Double.parseDouble(rateStr);
quantity=Double.parseDouble(quantityStr);
result=compute();
paymentText.setText(nf.format(result));
}
showStatus(" ");
}catch(NumberFormatException exc)
{
showStatus("invalid input");
paymentText.setText(" ");
}}
double compute()
{
double tax;
double pay;
double e;
double b;
tax=(quantity*price*intRate)/100;
pay=(quantity*price)+tax;

return pay;
}
}
This question has already been answered. Start a new discussion instead.