Welcome to Dream.In.Code
Become a Java Expert!

Join 149,840 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,440 people online right now. Registration is fast and FREE... Join Now!




getHost() and getFile() of URL

 
Reply to this topicStart new topic

getHost() and getFile() of URL

PennyBoki
13 Feb, 2007 - 08:20 AM
Post #1

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi, when I try to get the name and the host I recieve errors
which are commented in the code.
I don't know what is the problem...?

CODE
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;

public class Ispitna4
{
    
    public static void main(String [] args)
    {    
        
        try
        {
            String aaa= JOptionPane.showInputDialog("Enter an adress:");
            URL    adresa = new URL(aaa);
            String a=adresa.getFile();
            String b=adresa.getHost();
        }
        catch(MalformedURLException e)
        {
            System.out.println("Exception...");
        }
        
        System.out.println("File name: "+a); //cannot find symbol variable a
        System.out.println("Host name: "+b); //cannot find symbol variable b
    }
}


CODE
System.out.println("File name: "+a); //cannot find symbol variable a
        System.out.println("Host name: "+b); //cannot find symbol variable b


This post has been edited by PennyBoki: 13 Feb, 2007 - 08:21 AM
User is offlineProfile CardPM
+Quote Post

beef
RE: GetHost() And GetFile() Of URL
13 Feb, 2007 - 08:30 AM
Post #2

D.I.C Head
Group Icon

Joined: 2 Nov, 2006
Posts: 128


My Contributions
Try declaring your 2 strings outside of your try/catch block.
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: GetHost() And GetFile() Of URL
13 Feb, 2007 - 08:46 AM
Post #3

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(beef @ 13 Feb, 2007 - 09:30 AM) *

Try declaring your 2 strings outside of your try/catch block.



noup here I deleted the a and b variables
still dont work

CODE
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;

public class Ispitna4
{
    
    public static void main(String [] args)
    {    
        
        try
        {
            String aaa= JOptionPane.showInputDialog("Enter an adress:");
            URL    adresa = new URL(aaa);
        
        }
        catch(MalformedURLException e)
        {
            System.out.println("Exception...");
        }
        
        
        System.out.println("File name: "+adresa.getFile()); //cannot find symbol variable adresa
        System.out.println("Host name: "+adrsa.getHost()); //cannot find symbol variable adresa
    }
}


This post has been edited by PennyBoki: 13 Feb, 2007 - 08:47 AM
User is offlineProfile CardPM
+Quote Post

beef
RE: GetHost() And GetFile() Of URL
13 Feb, 2007 - 09:01 AM
Post #4

D.I.C Head
Group Icon

Joined: 2 Nov, 2006
Posts: 128


My Contributions
try this
CODE

    public static void main(String [] args)
    {    
        String a = "";
        String b = "";
        String aaa = "";
        URL adresa;
        try
        {
            aaa= JOptionPane.showInputDialog("Enter an adress:");
            adresa = new URL(aaa);
            a=adresa.getFile();
            b=adresa.getHost();
        }
        catch(MalformedURLException e)
        {
            System.out.println("Exception...");
        }
        
        System.out.println("File name: "+a); //cannot find symbol variable a
        System.out.println("Host name: "+b); //cannot find symbol variable b
    }


>Edit<
Sorry got in a rush and left a few bugs, I fixed them now.

This post has been edited by beef: 13 Feb, 2007 - 09:08 AM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: GetHost() And GetFile() Of URL
13 Feb, 2007 - 09:13 AM
Post #5

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Thanks man, I guess one have to declare the strings as emty and then
put them in atry block.
Anyways thank you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:56AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month