0

I have been having this weird problem with this small part of code:

if(isURL)
File audio = new File(name);
else
URL audio = new URL(name);

Now isURL is a pre-declared boolean and name is a pre-declared string. I have all the proper imports but for some reason or another it tells me that my declaritions of the variables are not statements; if I put them in brackets it does the same thing but if I take them out of the if-else statement, it works fine (well if you change the name of one of the variables). Anybody have any ideas on this issue.

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by jwenting
0

The entire thing you have there is not a valid Java statement.
What are you trying to achieve anyway? The variable would (were this to compile) be lost anyway as soon as it completed.

0

oh I totally forgot about scope within an if statement, that would explain my problem.

Basically what I'm trying to do is allow the user to input a path (a file path {without having to be file:// in front of it} or a URL path). The program figures out whether it is a file or a URL and then sets the isURL variable to true if the input was found to be a URL. Now I want to figure out what type of variable it is so I can handle the file or URL while having the same variable name.

Can you thing of a way to do this or should I just append file:// to a file Input string and just use the URL variable exclusively?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.