Simple lines now not compiling
I added the Netbeans profiler to my app this morning. I don't know if that has anything to do with my problem specifically, but for some reason, simple lines that I add in are acting very weird now. For instance, the below line asks for another " )". Without this line, the program compiles fine so I know it's not the result of another () not being closed. Both variables are strings. What am I not seeing?
System.out.println("Path of " + userURL"is " + pathURL);
[531 byte] By [
subnetrxa] at [2007-10-3 2:51:37]

> What am I not seeing? The little plus sign between 'userURL' and the string " is ".kind regards,Jos
JosAHa at 2007-7-14 20:40:30 >

You're missing a + after userURL
> > System.out.println("Path of " + userURL "is " +
> pathURL);
>
System.out.println("Path of " + userURL + "is " + pathURL);
You are missing the "+" in bold.
I wonder how many times this will be said.
Message was edited by:
jbish
jbisha at 2007-7-14 20:40:30 >

> I wonder how many times this will be said.Just consider us all quite a good Java parser but with a very wobblyerror message memoizer ;-)kind regards,Jos
JosAHa at 2007-7-14 20:40:30 >

> > I wonder how many times this will be said.> > Just consider us all quite a good Java parser but> with a very wobbly> error message memoizer ;-)> > kind regards,> > Jos: )
jbisha at 2007-7-14 20:40:30 >

Thanks, I knew I had to just be seeing things. I posted this after looking over a if else block that won't let me add the else because I "can't have an else without an if" eventhough there is an else if block right above it. With my code format, it see be very easy to see unclosed brackets, but I just don't see it. I would paste it here, but it's about 150 lines, so I'll just continue to stare aimlessly.
> post it...
All 150 lines? *shudder*. Vi can find matching parentheses and other
brackets by pressing the '%' key. Using eclipse you can do the same
by pressing CTRL-SHIFT-P. The op must have some way to figure that
out for him/herself.
kind regards,
Jos
JosAHa at 2007-7-14 20:40:30 >

yeah, I can go to every closing bracket in Netbeans and it will highlight the opening one. They are all there. I'll post the if block that I'm referring to to see if someone sees something that I don't:
if(tempURL.trim().startsWith(baseURL.toString()) && !tempURL.trim().toLowerCase().endsWith("js") && !tempURL.trim().startsWith("#"))
{
try
{
HttpURLConnection con = (HttpURLConnection) pageLinks[i].getRequest().getURL().openConnection();
int respcode=con.getResponseCode();
con.disconnect();
if (respcode != 200 || respcode != 202)
{
FileWriter writer = new FileWriter("Not_Found.txt", true);
writer.write(System.getProperty("line.separator") + pageLinks[i].getRequest().getURL());
writer.close();
}
else
{
WebLinkQueue.add(pageLinks[i].getRequest().getURL());
try
{
FileWriter writer = new FileWriter("Processed.txt", true);
writer.write(System.getProperty("line.separator") + pageLinks[i].getRequest().getURL());
writer.close();
}
catch(IOException e)
{
logger.debug("Could not write " + userURL + " to not processed file");
}
}
}
catch(java.net.MalformedURLException me)
{
logger.debug("pageLinks HTTPCon block: " + me.getMessage());
}
catch(java.io.IOException ie)
{
logger.debug("pageLinks HTTPCon block: " + ie.getMessage());
}
}
else if(!tempURL.trim().startsWith("#") && tempURL.trim().startsWith(baseURL.toString()));
{
notProcessed.add(pageLinks[i].getRequest().getURL().toString());
try
{
FileWriter writer = new FileWriter("Not_Processed.txt", true);
writer.write(System.getProperty("line.separator") + pageLinks[i].getRequest().getURL());
writer.close();
}
catch(IOException e)
{
logger.debug("Could not write " + userURL + " to not processed file");
}
}
else if(!tempURL.trim().startsWith("#")) //error here
{
try
{
FileWriter writer = new FileWriter("External.txt", true);
writer.write(System.getProperty("line.separator") + pageLinks[i].getRequest().getURL());
writer.close();
}
catch(IOException e)
{
logger.debug("Could not write " + userURL + " to not processed file");
}
}
here's your problemelse if(!tempURL.trim().startsWith("#") && tempURL.trim().startsWith(baseURL.toString()));get rid of that ; and it'll work fine.
There's a semicolon at the end of your first 'else if' line.kind regards,Jos
JosAHa at 2007-7-14 20:40:30 >

> There's a semicolon at the end of your first 'else> if' line.> > kind regards,> > JosToo slow old man ;-)
> > There's a semicolon at the end of your first 'else
> > if' line.
> >
> > kind regards,
> >
> > Jos
>
> Too slow old man ;-)
Indeed; I was just editing my previous reply where I wanted to add a line:
"and who's the slowest old sod again?"
But I was even too slow for that ;-)
kind regards,
Jos (them darn youngsters nowadays; no respect I'm telling ya)
JosAHa at 2007-7-14 20:40:30 >

wow, thanks. Why did it compile with the semi-colon in? Does it ignore it or does that tell the compiler something else?
Also, about my logic. Will that last else if just match and excute if it hasn't been matched by another else if, or will it match everything that returns true for that statement?
Message was edited by:
subnetrx
> wow, thanks. Why did it compile with the semi-colon
> in? Does it ignore it or does that tell the compiler
> something else?
I believe it tells the compiler that there isn't going to be any code in that block. There are rare situations where you'll want that, such as for abstract methods.
> Also, about my logic. Will that last else if just
> match and excute if it hasn't been matched by another
> else if, or will it match everything that returns
> true for that statement?
Like any other else block, an else-if block only executes if the original if and any previous else-ifs did not.
} else if (/*boolean*/) {
is basically just shorthand for
} else {
if (/*boolean*/) {
only with one fewer curved bracket to worry about.
> wow, thanks. Why did it compile with the semi-colon
> in? Does it ignore it or does that tell the compiler
> something else?
Because it is perfectly legal to have the semicolon after an if, else, else if, while or for statement. The compiler only complained after you added another else if (or else) statement. Look at the below code.
int num = 15;
if(num < 5)
{
System.out.print("foo ");
} else if(num > 10);
{
System.out.print("bar");
}
Output will be bar.Change the value of num to 3 and the output will be foo bar. The else if is terminated by the semicolon and does nothing but the print bar statement is out side the if/else if statement and will always be executed.
This is one reason I prefer the below coding standard as it is easier to spot this type of error.
if(conditiion) { // brace at end of line. should be obvious if you have a ; there