How to handle exception java.lang.reflect.InvocationTargetException


#1

java.lang.reflect.InvocationTargetException in java Applet
I have a simple java class file and the server throws this exception when I try to run this with an applet through an html file…
Here is all the code…

import javax.swing.* ;
import java.awt.event.* ;
class CalcApplet extends JApplet implements ActionListener
{

JPanel pnl = new JPanel();
JTextField txt1 = new JTextField(6) ;
JTextField txt2 = new JTextField(6) ;
JLabel lbl1 = new JLabel(“Number1 :”) ;
JLabel lbl3 = new JLabel(“Number2 :”) ;
JLabel lbl2 = new JLabel("") ;
JButton btn1 = new JButton( " Add " ) ;
JButton btn6 = new JButton( " Reset " ) ;
JButton btn2 = new JButton( “Sub” ) ;
JButton btn3 = new JButton( “Mul” ) ;
JButton btn4 = new JButton( “Div” ) ;
JButton btn5 = new JButton( “Mod” ) ;
// Creating constructor
public void init()
{
//super(“Calculator”);
//setSize(315, 200 );
//setDefaultCloseOperation( EXIT_ON_CLOSE );
add(pnl);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn6.addActionListener(this);

txt1.setText("") ;
txt2.setText("") ;

//pnl.add( img );

pnl.add( lbl1 );
pnl.add(txt1);
pnl.add( lbl3 );
pnl.add(txt2);
pnl.add(btn1);
pnl.add(btn2);
pnl.add(btn3);
pnl.add(btn4);
pnl.add(btn5);
pnl.add(btn6);
pnl.add( lbl2 );
//setVisible(true);
}
public void actionPerformed( ActionEvent event )
{
Float s;

if( event.getSource() == btn1) 
{
btn6.setEnabled( true ); 
s = Float.parseFloat( txt1.getText()) + Float.parseFloat( txt2.getText());
lbl2.setText("  Result is   : " + s ) ;
}	
if( event.getSource() == btn2) 
{
btn6.setEnabled( true ); 
s = Float.parseFloat( txt1.getText()) - Float.parseFloat( txt2.getText());
lbl2.setText("Result is : " + s ) ;
}
if( event.getSource() == btn3) 
{
btn6.setEnabled( true ); 
s = Float.parseFloat( txt1.getText()) * Float.parseFloat( txt2.getText());
lbl2.setText("Result is : " + s ) ;
}
if( event.getSource() == btn4) 
{
btn6.setEnabled( true ); 
s = Float.parseFloat( txt1.getText()) / Float.parseFloat( txt2.getText());
lbl2.setText("Result is : " + s ) ;
}
if( event.getSource() == btn5) 
{
btn6.setEnabled( true ); 
s = Float.parseFloat( txt1.getText()) % Float.parseFloat( txt2.getText());
lbl2.setText("Result is : " + s ) ;
}
if( event.getSource() == btn6) 
{
btn6.setEnabled( false ) ;
lbl2.setText("") ;
txt1.setText("");		
txt2.setText("");	
}

}
}