Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of URL, openConnection and URLConnection

Status
Not open for further replies.

CdnRebel

Programmer
Apr 5, 2003
39
CA
I'm trying to write a class to connect to a website. I've imported java.net.* and java.io.*, and on the following code
I keep getting a cannot resolve on hp:

URL hp = new URL("URLConnection conn = hp.openConnection();

I'm not familiar enough with the packages to know, if I'm using them properly; but as far as I can tell the code seems right. Can some one help? I can't see anything wrong.
 
Try to enclose you code in a try-catch block, that should give you error messages, if there are any.


try{
URL hp = new URL(" URLConnection conn = hp.openConnection();
}catch(Excpetion mfe){ System.out.println(mfe.toString());}
 
I left the try and catch statements out of my query because I thought they were a given. Nevertheless, I tried the try and catch statements in the manner suggested and my result was still the same. cannot resolve symbol
symbol: variable hp
location: class TestURL
URLConnection conn = hp.openConnection();
 
Don't know if this helps, I copyd and pated it.
The only difference I see is that the urlconnection is declared first and then opened (should not matter as far as I know).

URLConnection con;
StringBuffer strbufAll = new StringBuffer();
String str;
java.net.URL uu;
try{
uu = new URL(" con = uu.openConnection();
con.setDoInput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
while((intChar = in.read())!=-1){
strbufAll.append((char) intChar);
}
}catch(Exception e){
System.out.println(e.toString());
}
str = strbufAll.toString();
 
Thanks guys. My problem turned out to be too many trys and catches
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top