Can any one help me to solve my prblem

exception java.io.IOException is never thrown in body of corresponding try statement

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.text.*;

import java.util.Date;

import java.io.*;

publicclass SampleIO2

{

int[] u=newint[27];

JFrame f;

String s1,s2;

int v1,v2,v3,v4;double v5;

JButton b1,b2,b3;

JTextField []a=new JTextField[27];

int []p=newint[27];

JTextField t1,t2,t3,t4,t5,t6,t7,t8;

JLabel l1,l2;

public SampleIO2()

{

initializeFrame();

initializeComponents();

setButtonAction();

f.show();

}

publicvoid initializeFrame()

{

f =new JFrame("Kandil Softwares");

f.setBounds(300,250,700,400);

f.getContentPane().setLayout(null);

f.setResizable(false);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().setBackground(Color.GRAY);

}

publicvoid initializeComponents()

{

Date currentDate =new Date();

l1=new JLabel("NameSalery ");

l1.setBounds(10,5,385,20);

f.getContentPane().add(l1);

l2=new JLabel("Over Time :Ins : Salf :Total :");

l2.setBounds(5,180,385,20);

f.getContentPane().add(l2);

t1 =new JTextField();//total

t1.setBounds(350,180,100,20);

f.getContentPane().add(t1);

t2 =new JTextField();//name

t2.setBounds(20,30,80,20);

f.getContentPane().add(t2);

t3 =new JTextField();//over time

t3.setBounds(70,180,45,20);

f.getContentPane().add(t3);

t4 =new JTextField();//salery

t4.setBounds(280,30,50,20);

f.getContentPane().add(t4);

b1 =new JButton("Cal");

b1.setBounds(20,300,90,40);

f.getContentPane().add(b1);

b2 =new JButton("Save");

b2.setBounds(130,300,90,40);

f.getContentPane().add(b2);

b3 =new JButton("New");

b3.setBounds(240,300,90,40);

f.getContentPane().add(b3);

t5 =new JTextField();//ins

t5.setBounds(150,180,50,20);

f.getContentPane().add(t5);

t6 =new JTextField();//salf

t6.setBounds(250,180,50,20);

f.getContentPane().add(t6);

t7 =new JTextField();

t7.setBounds(20,225,50,20);

f.getContentPane().add(t7);

t8 =new JTextField();

t8.setBounds(20,250,50,20);

f.getContentPane().add(t8);

t1.setEditable(false);

// f.getContentPane().setBackground(Color.blue);

int q=60;

int s=60;

for(int i=0;i<27;i++){

a[i]=new JTextField();

a[i].setBounds(q,s,35,20);

f.getContentPane().add(a[i]);

q=q+40;

if ((i==6)||(i==13)||(i==20)){

q=60;

s=s+30;}

}

}

publicvoid setButtonAction()

{

b1.addActionListener(new ActionListener()

{

publicvoid actionPerformed(ActionEvent e)

{

//double[] p = new double[27];

// String[] n = new String[2];

if (t3.getText().length()==0)

v5=0;

else

v5=Integer.parseInt(t3.getText());

if (t4.getText().length()==0)

v2=0;

else

v2=Integer.parseInt(t4.getText());

if (t5.getText().length()==0)

v3=0;

else

v3=Integer.parseInt(t6.getText());

if (t6.getText().length()==0)

v4=0;

else

v4=Integer.parseInt(t6.getText());

double disc1=0,disc2=0,disc3=0;

double late1=0,late2=0,late3=0;

double rus =0;

int x=0,y=0,z=0;

double sum = 0;

double sal = v2;

double hafez =sal*0.05;

double dsal = sal/30;

for (int i=0 ;i<a.length;i++){

s1 = a[i].getText();

if(s1.length()==0)

v1=0;

elseif(s1.charAt(0)=='a'){

x++;}

elseif(s1.charAt(0)=='b'){

y++;}

elseif(s1.charAt(0)=='c'){

z++;}

else

{v1=Integer.parseInt(a[i].getText());}

int c=0;v1=p[i];

double minsal = sal /( 30 * 9 * 60) ;

double latemin = v1;

if (latemin ==0)

c++;

if ( latemin > 60 )

{

late1 = latemin - 60;

late2 = 30;

late3 = 30;

}

elseif ( latemin > 30 )

{

late1 = 0;

late2 = latemin - 30;

late3 = 30 ;

}

elseif (latemin <= 30)

{

late1 = 0;

late2 = 0;

late3 = latemin;

}

disc1 = late1 * 3 * minsal;

disc2 = late2 * 2 * minsal;

disc3 = late3 * 1.5 * minsal;

sum = disc1 + disc2 + disc3;

rus = rus + sum;

}

double ove=v5*1.5*(sal/(30*9));

double c1 = x*1.5*dsal;

double c2 = y*2*dsal;

double c3 = z*3*dsal;

double cs=c1+c2+c3;

double fsalery = sal+ove - (rus+cs+v3+v4);

t1.setText(""+fsalery+" ");

String w1=t2.getText();String w2=t7.getText();

// save(p,w1,w2,v3,v1,v4,v5,fsalery);

}

});

b2.addActionListener(new ActionListener()

{

publicvoid actionPerformed(ActionEvent e)

{

}

});

b3.addActionListener(new ActionListener()

{

publicvoid actionPerformed(ActionEvent e)

{

}

});

}

publicstaticvoid save(int[] q,String n,String c,int in,int sal,int salf,double over ,double total)throws IOException

{

DataOutputStream out =new DataOutputStream(new FileOutputStream("asd.txt"));

try{

int f=0;

}catch(IOException ioe){

ioe.printStackTrace();

for(int i = 0; i < q.length; i ++){

out.writeInt(q[i]);

out.writeChar('\t');

}

out.close();

}

}

publicstaticvoid main(String[] args)

{

JFrame f =new JFrame("Hello, World!");

int y=1;

/*JLabel myLabel = new JLabel("Hello, World!");

myLabel.setBounds(244, 240, 80, 40);

f.getContentPane().add(myLabel);

f.show();

*/

SampleIO2 g =new SampleIO2();

}

}

[12034 byte] By [kandilxa] at [2007-11-27 8:20:20]
# 1

public static void save(int[] q,String n,String c,int in,int sal,int salf,double over ,double total)throws IOException

{

DataOutputStream out = new DataOutputStream(new FileOutputStream("asd.txt"));

try{

int f=0;

}catch(IOException ioe){

ioe.printStackTrace();

for(int i = 0; i < q.length; i ++) {

out.writeInt(q[i]);

out.writeChar('\t');

}

out.close();

}

This section?

Nothing will get thrown because your code that would throw an exception is not in the try. You want to do something like this maybe...

public static void save(int[] q,String n,String c,int in,int sal,int salf,double over ,double total)throws IOException

{

DataOutputStream out = null;

try{

out = new DataOutputStream (new FileOutputStream ("asd.txt"));

int f=0;

for(int i = 0; i < q.length; i ++) {

out.writeInt(q[i]);

out.writeChar('\t');

}

out.close();

}catch(IOException ioe){

ioe.printStackTrace();

if (out != null) { out.close(); }

// note: your declaration has a throws IOException, which means you

// don't need this try catch block here. If you wanted to contain it and add your

// own error message, this would be fine, and you say something along the

// lines of throw new IOException ("An Error Occured"); in the catch section.

//Then your throws IOException in your declaration would make sense. So

// either take out the try catch block, and if an exception is thrown, the calling

// method would have to catch it, keep it to contain it and throw your own error // message or keep it and contain it but take out the throws IOException from // your declaration

}

kdajania at 2007-7-12 20:08:37 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...