Link to home
Start Free TrialLog in
Avatar of max_dub
max_dubFlag for Ireland

asked on

for loop

code shown below..

index[0] and index[1] have values 0 and 6 resp.

but the programs comes out of loop after checking 6 value

am missing something??
for(int m=0; m<12; m++) {
   if(m==index[0] || m==index[1]) {
	log.info("keeping "+m+" instance");
   } else {
	log.info("delete "+m);
	startingData.delete(m);
}
}

Open in new window

Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

Can you post the rest of code, please.
It seems to me that for loop must have 12 iterations.
Avatar of CEHJ
Make sure you're not ignoring exceptions
whats the log show?
Avatar of max_dub

ASKER

that is pretty much the code where runtime error comes

log shown below

as per exceptions, the only thing i need to check is if the counter equals either if index value .. keep data .. otherwise delete data

but somehow it doesn't loop entirely upto 12
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - image 1 to delete: 0
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - image 2 to delete: 6
 
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - Starting data: 12
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - keeping 0 instance
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - delete 1
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - delete 2
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - delete 3
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - delete 4
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - delete 5
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - keeping 6 instance
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - Starting data: 7
2007-11-20 23:23:16,406 INFO  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - Query Data: 10
2007-11-20 23:23:16,406 WARN  SwingWorker-pool-1-thread-9 BuildClassifierHelper [] - All Loaders Spawned

Open in new window

Avatar of max_dub

ASKER

ok, it seems to give arrayoutofbounds exception for no. 7

debugging now
>>as per exceptions, the only thing i need to check is if the counter equals either if index value .. keep data .. otherwise delete data

It's doesn't really matter what you're doing. You can get an exception almost anywhere - often terminating the thread
>>ok, it seems to give arrayoutofbounds exception for no. 7

(A RuntimeException )
get a stack trace f the exception, ando stop it breaking yo looppp use;

for(int m=0; m<12; m++) {
   if(m==index[0] || m==index[1]) {
        log.info("keeping "+m+" instance");
   } else {
        log.info("delete "+m);
        try {
           startingData.delete(m);
        } catch (Exception ex) {
           ex.printStackTrace();
        }
}
}
Avatar of max_dub

ASKER

yeah, after 6

it throws array out of bounds

java.lang.ArrayIndexOutOfBoundsException
      at java.lang.System.arraycopy(Native Method)
      at weka.core.FastVector.removeElementAt(Unknown Source)
      at weka.core.Instances.delete(Unknown Source)

wondering as the object does contains 12 instances?
You need to do some more debug to find out why
Avatar of max_dub

ASKER

yeah, when i am individually deleting the values it works fine

but not as a whole, i suppose its shifting the values in between

thanks for help!!
No problem
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of max_dub

ASKER

wow, i was thinking of doing same, but then i thought probably it won't work.. its just the otherway round.. but its does work :)

so actually i was debugging it and each time i was delete an instance, it was shifting it upwards and when it reached 7, it was already out of that reach .. hence the array out of bounds

now i wonder, why wud from 11 to 0 work and not 0 to 11??
?
Avatar of max_dub

ASKER

i don't knw ??

somehow it works otherway around - from 11 to 0 .. mebbe experts can say why

thou what i was trying to do was to delete each instance individually and once it deletes an instance, i updated the count so that it deletes the right index and no exception then

but objects sol. worked too.. i still need to figure it out why?
as i mentioned above you won't have 12 after you start removing them.