Results 1 to 5 of 5
- 01-11-2013, 05:50 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
need help with if statement in loop
Apparently I don't understand conditional statements. I have a loop, and in the first iteration I need something to happen. The statement in my if (i==0) never executes. Basically I want to create a new ImageStack when the first image in the loop is loaded. Can some one tell me what I am doing wrong here?
Java Code:for (int i=0; i<files.length; i++) { ImagePlus img = opener.openImage(path, files[i].getName()); if (i==0) { ImageStack stack = new ImageStack(img.getWidth(), img.getHeight(), 2); } if (img!=null) { img.show(); stack.addSlice(files[i].getName(),img.getProcessor().getPixels()); } }
Edited: I guess I should add my error message when I compile:
C:\Program Files (x86)\ImageJ\plugins\Gallery_File_Opener.java:61: cannot find symbol
symbol : variable stack
location: class Gallery_File_Opener
stack.addSlice(files[i].getName(),img.getProcessor().getPixels());
^
1 errorLast edited by Snackers; 01-11-2013 at 05:55 PM. Reason: add more info
- 01-11-2013, 06:05 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: need help with if statement in loop
The variable 'stack' is local to that first if-statement body; define it before line #3 and it still exists in the second if-statement.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-11-2013, 07:33 PM #3
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Re: need help with if statement in loop
Java Code:ImageStack stack = null; for (int i=0; i<files.length; i++) { ImagePlus img = opener.openImage(path, files[i].getName()); if (i==0) { stack = new ImageStack(img.getWidth(), img.getHeight(), 2); } if (img!=null) { img.show(); stack.addSlice(files[i].getName(),img.getProcessor().getPixels()); } } .... stack = null; // In Last
- 01-11-2013, 07:58 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: need help with if statement in loop
Setting a (non existent) variable to null doesn't help one bit.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-11-2013, 08:04 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
repeat if statement in loop
By eng_hyzoom in forum New To JavaReplies: 5Last Post: 03-05-2012, 01:34 PM -
If Else Statement in While Loop
By rockintyler in forum New To JavaReplies: 3Last Post: 02-24-2012, 12:33 AM -
Help with loop statement
By arvind1508 in forum New To JavaReplies: 2Last Post: 02-23-2011, 05:39 PM -
Need help with a loop statement
By sunshine39 in forum New To JavaReplies: 7Last Post: 11-03-2008, 04:42 AM -
Least To Greates[ if statement and for loop]
By kris09 in forum New To JavaReplies: 1Last Post: 08-08-2008, 07:34 PM
Bookmarks