| | |
Suspected Vector Trouble
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 60
Reputation:
Solved Threads: 0
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
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:
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
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
![]() |
Other Threads in the Java Forum
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





