views:

141

answers:

2

hi every one ..

i'm an it student , and it's time to finish my final project in java , i've faced too many problems , this one i couldn't solve it and i'm really ubset ! :S

my code is like this :

in Admin class :

 public ArrayList cos_info = new ArrayList();
 public ArrayList cas_info = new ArrayList();
 public int cos_count = 0 ;
 public int cas_count = 0 ;


void coustmer_acount() throws FileNotFoundException, IOException{
String add=null;
 do{
    person p = new person() ;
    cos_info.add(cos_count, p);
    cos_count ++ ;
     add =JOptionPane.showInputDialog("Do you want to add more  coustmer..\n'y'foryes ..\n 'n'for No ..");
     }

   while(add.charAt(0) == 'Y'||add.charAt(0)=='y');
   writenew_cos();
  // add_acounts();
   }

    void writenew_cos() throws IOException{
    ObjectOutputStream aa = new ObjectOutputStream(new FileOutputStream("coustmer.txt"));
    aa.writeObject(cos_info);
    JOptionPane.showMessageDialog(null,"Added to file done sucessfuly..");
    aa.close();
     }

in Coustmer class :

void read_cos() throws IOException, ClassNotFoundException{
 person p1= null ;
 int array_count = 0;
 ObjectInputStream d = new ObjectInputStream(new FileInputStream("coustmer.txt"));
 JOptionPane.showMessageDialog(null,d.available() );
        for(int i = 0;d.available() == 0;i++){
        a.add(array_count,(ArrayList) d.readObject());
         array_count++;
        JOptionPane.showMessageDialog(null,"Haaaaai :D" );
        JOptionPane.showMessageDialog(null,array_count );
       }
       d.close();
       JOptionPane.showMessageDialog(null,array_count +"1111" );
             for(int i = 0 ; i<array_count&& found!= true ; i++){
            count ++ ;
            p1 =(person)a.get(i);
            user=p1.user;
            pass = p1.pass;
           // cos_checkpass();
                                    }
                        }

it just print JOptionPane.showMessageDialog(null,d.available() ); and having excep. here a.add(array_count,(ArrayList) d.readObject()); p.s : person object from my own class and it's Serializabled

A: 

Pretty sure any class you write should not throw ClassNotFoundException

bwawok
A: 

I would suggest putting a try/catch around your method call that throws the exception in the catch

catch(Exception ex){
ex.printStackTrace();
}

to find out where the error is coming from exactly, it might give you more information that what you're getting.

Also, I would recommend using

JOptionPane.showMessageDialog(null, "Add more Customers?", "Continue?",JOptionPane.ERROR_MESSAGE);

or something like that rather than getting the character of what the user typed, it creates a more user friendly interface.

EricR