Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Problem with url.openConnection() is undefined and am completly new to java, here is a sample code i got online :


Java
HttpURLConnection connection = null;       
		String semifinalUrlString = "http://www.google.com/";  
		URL url = new URL(semifinalUrlString);      
		connection = (HttpURLConnection)url.openConnection();      
		connection.connect(); 



What am I missing to get the openConnection()?
Posted

1 solution

One possible reason may be missing proper imports. There must be imports like:
Java
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

For more you can have a look on discussion here:
http://stackoverflow.com/questions/9977221/open-url-in-java-to-get-the-content[^]

Hope that issue will be resolved, if not please update us with new error message u get. Thanks.
 
Share this answer
 
Comments
Anele Ngqandu 13-Jan-15 2:37am    
The java.net.URL conflicts with the type defined in the same file and also the openConnection() is not defined
Snesh Prajapati 13-Jan-15 3:20am    
In that case..what if you use fully qualified names. If the term "fully qualified name" is new to you....please have a look on http://stackoverflow.com/questions/17875823/how-to-resolve-class-name-to-fully-qualified-in-java
Snesh Prajapati 13-Jan-15 3:22am    
One more useful link: http://programmers.stackexchange.com/questions/131499/what-are-the-reasons-one-would-use-fully-qualified-class-names-in-source-code
Anele Ngqandu 13-Jan-15 3:56am    
thanks ill have a look.
Snesh Prajapati 13-Jan-15 3:57am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900