0

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?

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
ashu
  • 1,339
  • 7
  • 27
  • 43

3 Answers3

2

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()

Wayan Wiprayoga
  • 4,472
  • 4
  • 20
  • 30
1

Check your import for the URL class. It should be

import java.net.URL;
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
0

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

jj88
  • 91
  • 1
  • 7