ashu
ashu

Reputation: 1359

Error in HttpURLConnection - openConnection

I am having the following java function for check the website responce code:

URL u = null;   

try {
    u = new URL("http://bforball.com");
    HttpURLConnection huc =  ( HttpURLConnection ) u.openConnection (); 
    huc.setRequestMethod ("GET"); 
    huc.connect () ; 
}

I have imported the below:

import java.net.HttpURLConnection;

But when I compile my code I am getting warning message near

u.openConnection

Warning message:

Connot find the symbol
Symbol: mehod openConnection()
Location:variable u of type URL

What I am doing wrong?

Upvotes: 0

Views: 1734

Answers (3)

Wayan Wiprayoga
Wayan Wiprayoga

Reputation: 4562

I guess you have wrong import on URL class. You have to import URL with correct package :

import java.net.URL;

It has method openConnection()

Upvotes: 2

jj88
jj88

Reputation: 91

Maybe URL class which you used doesn't have an openConnection() method?

Upvotes: 0

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

Check your import for the URL class. It should be

import java.net.URL;

Upvotes: 1

Related Questions