Suspected Vector Trouble

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Suspected Vector Trouble

 
0
  #1
Oct 12th, 2008
Hi. I am attempting to update a Jtable with details of all the files on my computer. I am running Windows XP home edition version 2002 with service pack 3. Intel(R) pentium(R) 4 CPU 3.20 GHz

 for (int i = 0; i<r.size(); i++)
            {
                Vector v = new Vector();
                {  
                     String s;
                     long d = ((File)r.elementAt(i)).lastModified();
                      
                     java.util.Date dat1 = new java.util.Date(d);
                     s = String.valueOf(dat1);
                     contents[i].getAbsolutePath());
                     v.addElement((String)((File)r.elementAt(i)).getName());
                     v.addElement((String.valueOf(((File)r.elementAt(i)).length())));
                     v.addElement((String)s);
                     v.addElement((String)((File)r.elementAt(i)).getAbsolutePath());
                     rows.addElement(v);  
                     table.addNotify();  
                     System.out.println(i);
                     
                    }
                }

Other code I have not published looks up all the files on my computer to put it in a JTree while this is happening I store all files the field Vector r. Then this loop updates the table rows. My problem is the program freezes. The reason I print i was to get printed confirmation that the loop is traversing the vector. The program has completed once and updated the table as it is supposed to; so in this respect I know it works. However, 9 of 10 times it freezes. I have only tested on 1 computer because well I only have 1. Could it be that I need a java update of some sort? Or perhaps just my computer? I suspect it is the Vector because initially I did this:

public void search() 
    {
        File[] contents = path.listFiles();  
       try
       {    
            for (int i = 0; i<contents.length; i++)
            {
                Vector v = new Vector();
                if(contents[i] != null)
                {
                    if (contents[i].isDirectory())
                    {   
                        search(contents[i].getAbsolutePath(), find); 
                
                    }
                    else
                    {  
                        String s;
                        long d = contents[i].lastModified();
                         
                        java.util.Date dat1 = new java.util.Date(d);
                        s = String.valueOf(dat1);
                        contents[i].getAbsolutePath());
                        v.addElement((String)contents[i].getName());
                        v.addElement((String.valueOf(contents[i].length())));
                        v.addElement((String)s);
                        v.addElement((String)contents[i].getAbsolutePath());
                        rows.addElement(v);  
                        r.addElement(contents[i].getAbsolutePath());
                        table.addNotify();  
                        
                    }
                }
            }
        }
        catch(Exception e)
        {
             System.out.println("Following Exception occured  - " + e);
        }
     }

This works 100% the first method works faster in theory because the vector has already filtered out directories so the loop is shorter.
Your help would be appreciated
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Suspected Vector Trouble

 
0
  #2
Nov 16th, 2008
However, 9 of 10 times it freezes.
Give us more info, eny error... stack overflow?
quuba
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Suspected Vector Trouble

 
0
  #3
Nov 17th, 2008
Sorry, No information was given, it simply stopped. It did not throw an exception or anything at all. I have since rewritten the the code to make comparisons outside of the vector but I never got a solution to the original problem.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC