Web Hosting Talk







View Full Version : Java URL error


ruski
08-09-2006, 12:22 AM
Hi,

Im just making a stupid java program to practise some regex because Im new to it and came across an annoying error with the URL declaration, here is the error:


ForumHacker.java:91: cannot find symbol
symbol : constructor URL(java.lang.Object)
location: class java.net.URL
URL u = new URL(LineList.get(1));
^


I was thinking this is because im declaring the URL a second time in the class file, but in different voids, as you can see here:



public static void FetchLinks(String directory)
{
int pnum = 1;
while(pnum < 5)
{
try {
URL url = new URL("linklinklinklink");
URLConnection con = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

//and so on





public static void getPicLinks()
{

try {

URL u = new URL(LineList.get(1));
URLConnection ucon = u.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
System.out.print(in.readLine());

} catch(Exception e) { System.out.print(e); }

}




Some help would be greatly appritiated

Thanks in advance

stdunbar
08-09-2006, 11:24 AM
Hi,

Im just making a stupid java program to practise some regex because Im new to it and came across an annoying error with the URL declaration, here is the error:


ForumHacker.java:91: cannot find symbol
symbol : constructor URL(java.lang.Object)
location: class java.net.URL
URL u = new URL(LineList.get(1));
^



The problem is that LineList.get() is returning an Object and the URL constructor wants a String. You'll need to cast like:


URL u = new URL((String)LineList.get(1));


This is assuming that you're on Java 1.4 and below. In Java 1.5 you would be strongly encouraged to use generics so that your LineList object could return the correct type on a get() call.

ruski
08-09-2006, 03:50 PM
Thanks a lot, fixed