First Time With The URL Class

Okay, I've been exploring the various classes available in Java, in the hope of building a web-indexer (more as an exercise in Java than anything useful). However, I've been snagged fairly early on, in that I can't even call the class constructor...
Here's what I've got so far, for the class (called WebDoc):
import java.net.URL;
public class WebDoc {
    WebDoc( URL myURL) {
        System.out.println("This method works");
}and for the test program:
import WebDoc.*;
public class WebIndexerTest1 {
    public static void main(String[] args) {
        WebDoc myDoc = new WebDoc("http://www.dcs.shef.ac.uk/~martin/test1.htm");
}The WebDoc class has compile successfully, and is in the WebDocClass folder, in the correct place.
At the moment, it throws the error:
WebIndexerTest1.java [5:1] cannot access WebDocClass.WebDoc
bad class file: C:\Documents and Settings\Joseph Lloyd\My Documents\Uni\OOPing\WebIndexer\WebDocClass\WebDoc.class
class file contains wrong class: WebDoc
Please remove or make sure it appears in the correct subdirectory of the classpath.
        WebDoc myDoc = new WebDoc("http://www.dcs.shef.ac.uk/~martin/test1.htm");
        ^
1 errorwhich I assume means it can't find the WebDoc class. I can't see why not though. Can anyone help me out with this? I'm pretty sure it's something fairly obvious, but unfortunately not to me...

Cheers for the input, especially about packages. It's been quite a bit since I last touched Java, and I've forgotten most of the syntax.
After looking over the code, it's now modified to the following, but still throws up the original error that prompted me to start messing about with importing (for some reason). The WebDoc code is identical to before, but the test program has changed:
import java.net.URL;
public class WebIndexerTest1 {
    public static void main(String[] args) {
        String myString = "http://www.dcs.shef.ac.uk/~martin/test1.htm";
        URL myURL = new URL(myString);
        WebDoc myDoc = new WebDoc(myURL);
}However, it still throws the following error, and I have, after perusing the documentation and help files, no idea on how to deal with it (I assume I should have some kind of exception handler there, but I don't see why the URL class is throwing the exception in the first place...):
WebIndexerTest1.java [6:1] unreported exception java.net.MalformedURLException; must be caught or declared to be thrown
        URL myURL = new URL(myString);
                    ^
1 error
Errors compiling WebIndexerTest1. Any further help would be greatly appreciated, as this has been winding me up all day, and I apologise in advance if I'm displaying excessive stupidity in not noticing glaring errors...
Cheers

Similar Messages

  • Please help with the URL class

    Hello,
    I am trying to write a Java app that will take a url and download it.
    I believe you can do this with the URL class but I don't understand how to. For example, if the http url location points to a picture file, how would I code the app to retrieve this picture and save it to a specified directory?
    Also, is there a way that my java app could open another program, let's say Microsoft Internet Explorer?
    Please be as specific as possible, thanks!

    You'll see below an example to download a file
    private static String copyFile (String url, String nomFichier){
         // construction du fichier de sortie
         File outputFile = new File(repertoire + "\\fichiers\\" + nomFichier);
         // si le fichier existe d�j�, il ne sert � rien de le t�l�charger !
    if (outputFile.exists())
         return "fichiers/" + nomFichier;
              try {     
         HttpURLConnection connect = (HttpURLConnection)new URL(url).openConnection();
    boolean connected = false;
    while (!connected){
    try {
    connect.connect();
    connected = true;
         catch (java.io.IOException e1) { System.out.print("...Tentative de connection"); }     
    DataInputStream reader = new DataInputStream(
    connect.getInputStream());
         FileOutputStream out = new FileOutputStream(outputFile);
         int length = 1024;
         byte[] buf = new byte[length];
         int offset = 0;
         long offsetCourant = 0;
         int nb=0;
         while ((nb=reader.read(buf,offset,length))!= -1) {
              out.write(buf,0,nb);
         out.close();
         catch (java.net.MalformedURLException e) { System.out.println("pb d'url"); }
         catch (java.io.IOException e1) { System.out.println(e1.getMessage()); }
         return "fichiers/" + nomFichier;
    }

  • I live in Italy and I am trying to buy an App, for the first time with my iphone4...in the past only downloaded free apps free apps; I have a US Visa card and it is not accepted by italian Itunes...what can I do to do my purchases?

    I live in Italy and I am trying to buy an App, for the first time with my iphone4...in the past only downloaded free apps free apps; I have a US Visa card and it is not accepted by italian Itunes...what can I do to do my purchases?

    On the apple website that is correct i beleive.... but i have an italian american express and am able to purchase stuff here in the US.
    I mean, i dont think it really matters

  • I'm trying to use my iPad mini for the first time with a previous apple ID and password but it will not connect to iTunes but I can download apps from my iPhone using the same appleID and password and it works on my iphone...PLEASE HELP NOW

    I'm trying to use my iPad mini for the first time with a previous apple ID and password but it says "iTunes is not working try again"...it allowed me to download an app on my iPhone using the same apple ID & password but all my apps are in "Waiting Status" on my iPad mini because it says "iTunes is not working"...PLEASE HELP ME NOW!!!

    Previous user installed iOS 7 beta on that iPhone.
    Take it back and get your money returned. You
    are running into a new security feature. Whoever owns
    the ID that it is asking for is the only person who can
    remove the security. That iPhone is worthless to you.

  • I have itune on my first computer, but i cant download it for my other one,how can i do that, i tryed many time with the link it says you download it but nothing follows  thank you

    I have itune on my first computer, but i cant download it for my other one, how can i do that, i tryed many time with the link it says you download it but nothing follows  thank you

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/itunes/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

  • I decided to backup for the first time with icloud yesterday, and lost all my phone contacts! I am panicking, because the backup says 0, and I checked the internet account on my pc, and it's only showing email addresses from my hotmail account. What to do

    I decided to backup for the first time with icloud yesterday, and lost all my  phone contacts! I am panicking because the backup is saying 0 and I checked the internet account on my pc,and it's only showing email addresses from my hotmail account. What to do? How to recover them!

    Have they also gone from iCloud.com when you log in from a computer.

  • HT4859 How long should it take to back up iphone for the first time with about 6 gigs?

    How long should it take to back up iphone for the first time with about 6 gigs?

    Welcome to the Apple Community.
    The first back up to iCloud may take some considerable time. Just how long isn't really possible to say without knowing how much is in your back up and your connection speed.
    What many people don't realise is that upload speeds are often significantly less than download speeds, so for example a user may have a download speed of 40 Mbps, but only 1 Mbps for uploading. As a rough guide it will take around 2 ¼ hours to upload 1 GB of data at 1 Mbps.

  • I've tried to update my i-Tunes version after the site suggested I should following my i-Pad being plugged into it for the first time. The update seemed successful but the program would not open at all despite switching off the PC and re-starting several

    I’ve tried to update my i-Tunes version after the site suggested I should following my i-Pad Air being plugged into it for the first time. The update seemed successful but the program would not open at all despite switching off the PC and re-starting several times. I then tried wiping the original software from the computer and re-downloading from scratch. Each time I tried the download failed with a message saying “Service “Apple Mobile Device” failed to start. Verify that you have sufficient privileges to start system services” At this stage, the only way forward was to “abort” the download. This I have done now four times and the same thing happens. When I did finally manage to get an i-Tunes shortcut on my desktop, the program wouldn’t open saying: “i-Tunes was not installed correctly. Please re-install i-Tunes. Error 7 (Windows error 193)” Any ideas to resolve this?

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • ExecuteQuery WhereClause problem for first time in the session of the page

    I am new to OAF and I have panic problem.
    I have two pages application like following..
    First page “LookupTypes” and second page “LookupValues” for the selected first page Lookuptype.
    The problem is when I press first time(after lunching the page/first time for the session) the button in “LookupType” page I am getting all the “Lookup Values” for all the lookup types instead of getting only for one Lookuptype and I will press “back” button in “Lookup Values” Second page to come back “LookupType” first page, Again immediately I will press the same button which I pressed first time, this time I will get correct number of records for one Lookup Type. I don’t know why its where clause is not working first time.
    Please find the following code and help me.
    First page is LookupTypes->second page is Lookup Values
    Step 1 : I have button on “Lookup Types” page to call “Lookup values” page
    Step 2 : “Lookup Values” page control to receive the parameters from lookup type page.
    Step 3 : application module (AM) to execute the query..
    Code :
    Step 1 : I have button on “Lookup Types” page to call “Lookup values” page
    Following is the code from “Lookup Types” control.
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    String paramLookupTypeAction = pageContext.getParameter(EVENT_PARAM) ;
    String paramLookupType = pageContext.getParameter("paramLookupType");
    OAApplicationModule PafLookupAM = pageContext.getApplicationModule(webBean);
    //Adding calling LookUp Values screen
    if (paramLookupTypeAction.equals("viewLookupValues") )
    // PafLookupAM.invokeMethod("clearLookupValueMethod");
    //Here we prepare the HashMap object, that cotains name of the parameter and the value of the parameters
    HashMap phm = new HashMap() ;
    phm.put("xxparamLookupType",paramLookupType);
    phm.put("xxparamLookupTypeAction",paramLookupTypeAction);
    pageContext.setForwardURL(
    "OA.jsp?page=/oracle/apps/xxpaf/pafLookups/webui/pafLookupValuesPG"
    , null //not needed as we are retaining menu context
    ,OAWebBeanConstants.KEEP_MENU_CONTEXT
    ,null //not needed as we are retaining menu context
    ,phm //pass the hashMap that contains values for all of the parameters
    ,true //retain AM
    ,OAWebBeanConstants.ADD_BREAD_CRUMB_NO
    ,OAWebBeanConstants.IGNORE_MESSAGES);
    Step 2 : Following is the code from “Lookup Values” page control to receive the parameters from lookup type page.
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    String paramLookupTypeAction=pageContext.getParameter("xxparamLookupTypeAction");
    String paramLookupType=pageContext.getParameter("xxparamLookupType");
    OAApplicationModule PafLookupAM = pageContext.getApplicationModule(webBean);
    Serializable LookupTypeParamList[]= {paramLookupTypeAction,paramLookupType};
    System.out.println("viewLookupValues 3 " + paramLookupType);
    System.out.println("viewLookupValues 4 " + paramLookupTypeAction);
    if ( paramLookupTypeAction!=null && paramLookupTypeAction.equals("viewLookupValues"))
    System.out.println("viewLookupValues 5 " + paramLookupType);
    System.out.println("viewLookupValues 6 " + paramLookupTypeAction);
    PafLookupAM.invokeMethod("viewLookupValuesMethod", LookupTypeParamList);
              // Assuming the controller is associated with the pageLayout region
    // import oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean;
         //     OAPageLayoutBean page = (OAPageLayoutBean)webBean;
         //     page.setTitle("Lookup Type: " + paramLookupType);
    Step 3 : Following is the code from application module (AM) to execute the query..
    public void viewLookupValuesMethod( String pAction, String pLookupType)
    try
    OAViewObjectImpl pervo = getPafLookupValuesEOVO();
    String existingWhereClause = pervo.getWhereClause();
    pervo.setWhereClauseParams(null);
    pervo.setWhereClause("Lookup_Type = :1");
    pervo.setWhereClauseParam(0, new String (pLookupType));
    pervo.executeQuery();
    pervo.setWhereClauseParams(null);
    pervo.setWhereClause(existingWhereClause);
    catch(Exception exception1)
    throw OAException.wrapperException(exception1);
    Best Regards,
    Pathi TVB

    Pathi,
    Please try to have the WhereClause in the VO query as part of static definition itself. So you would only need to bind the parameter and execute the Query.
    Try and let me know if that helped.
    Thanks
    Sumit

  • Ever since installing on my 64bit Windows 7 install, Firefox has continually gotten more sluggish as time moves on, hangs for 10-15 secs at a time and just gets worse over time with the updates and everything.

    Ever since installing on my 64bit Windows 7 install, Firefox has continually gotten more sluggish as time moves on, hangs for 10-15 secs at a time and just gets worse over time with the updates and everything. It was fast when I first installed, but over the last six mos has slown to a crawl.

    upgrade your browser to Firefox 8 and try
    * getfirefox.com

  • I made in app purchase, didn't work the first time, made the purchase a second time

    I made in app purchase, didn't work the first time, made the purchase a second time

    Whatever your question might be, no one here can help with in-app purchases. You need to get in touch with iTunes support. http://support.apple.com/kb/ht1933

  • My iPhone 5 gives a busy tone whenever someone calls the first time. The person has to call a second time for the ringtone to be heard? How o I tux this issue? I have a missed call every time and then a ringtone.

    My iPhone 5 gives the caller a busy tone the first time when the phone is actually not in use. The caller has to make another call to get the ringtone. I will get the first call as missed with no ringtone and then the second time it will ring. What can be fond to solve this problem ?

    Turn off Do Not Disturb.
    http://support.apple.com/kb/HT5463?viewlocale=en_US&locale=en_US

  • First time with Arch, minimal build: little niggles [solved]

    Ok, I've been using *Buntu based Distros for a while now, this is my first time taking the plunge with Arch - chosen because it is a build in what you want distro.
    I've wanted a minimal build install for a printserver project, this week I took the plunge with an old laptop.
    I have it doing the printserver part, but there are some minor niggles. Let me detail what I have installed and what I want it to be able to do, before I detail these.
    Arch Base install with:
    CUPS
    LXDE
    Leafpad
    Xorg Intel video drivers.
    smartmontools
    firefox
    WPA_Supplicant,as this system is to be a wireless printserver.
    What I want this system to do:
    Run most of the time in shell, no DE running. (This keeps it cool and quiet, as it is in a bedroom)
    Only run the DE when startx is called, and have the DE able to be shut down without restarting the server.
    serve printjobs from the moment it boots and connects to the wireless.
    What it currently does.
    Boot up, wait for login
    When login, require WPA_supplicant, dhcpcd and Cupsd to be initialised before it can serve printjobs.
    If DE is required, Xorg must be started in tty1, startlxde ran in tty2, and then manually switch to tty7 for the DE.=
    I have a script to call when i login which starts WPA_Supplicant, dhcpcd, and cupsd in that order.
    I would really like the interface to have a staticip but i dont know how to do that without the handy graphical tools that ubuntu provides.
    Please can you help, at least point me in the right direction with these niggles? I have learned a lot about what is required to get a basic DE up and running, and im sure with your help I will learn more.
    Last edited by Rhiadratech (2011-05-20 23:07:52)

    Ok, so I've gotten Cups and wicd autostarting, set the static ip from my router because else it wasnt getting DNS etc details and left it asking for that by dhcp.
    Still having issues with the DE
    pedro_sland wrote:
    If DE is required, Xorg must be started in tty1, startlxde ran in tty2, and then manually switch to tty7 for the DE.
    I run xfce4 sometimes. I just run startxfce4 and it starts Xorg and displays the DE. I think that startx runs twm which you probably don't want so you might want to take a look at that. startx has a script it runs somewhere (I forget where but the wiki will know). When I'm done with xfce I just log out and it exits.
    For me, this isnt working. startlxde on its own just goes to
    [root@yomiko ~]#
    in tty1, and leaves me with a blank screen when i switch to tty7
    I literally must call Xorg in one tty, startlxde in another and then manually shift to tty7 to see it.
    startx itself:
    -bash: startx: command not found
    Even Xorg isnt happy being called on its own, that too goes to a blank screen, though it does at least switch to tty7
    With Xorg called in tty1, when i call startlxde in tty2 i get dbug errors from pcmanfm though these seem to be just it informing its detected the HDD partitions.
    there is a grumble early on in the process, before the debug errors, saying:
    Importing pynotify failed, notifications disabled.
    Finally, I did add the line to .xinitrc the LXDE page in the wiki said to to allow startx to run:
    exec ck-launch-session startlxde
    This is the only line in this file.
    Currently running as root... I'm not going to complicate matters by adding a user until im sure i got it all running as root, bad practice or not!
    Edit: A friend helped me solve it.
    The package xorg-xinit held the startx script that was missing. I now get LXDE when i want and only when I want.
    Last edited by Rhiadratech (2011-05-20 23:09:16)

  • XML Publisher(XDODTEXE) in EBS taking more time with the same SQL in TOAD

    HI
    XML Publisher(XDODTEXE) in EBS taking more time with the same SQL in TOAD.
    The sql has 5 union clauses.
    It takes 20-30 minutes in TOAD compared to running through Concurrent Program in XML Publisher in EBS taking around 4-5 hours.
    The Scalable Flag at report level is turned on with the JVM options set to -Xmx1024m -Xmx1024m in Concurrent Program definition.
    Other configurations for Data Template like XSLT, Scalable, Optimization are turned on though didn't bounce the OPP Server for these to take effect as I am not sure whether it is needed.
    Thanks in advance for your help.

    But the question is that how come it is working in TOAD and takes only 15-20 minutes?
    with initialization of session ?
    what about sqlplus ?
    Do I have to set up the the temp directory for the XML Publisher report to make it faster?
    look at
    R12: Troubleshooting Known XML Publisher and E-Business Suite (EBS) Integration Issues (Doc ID 1410160.1)
    BI Publisher - Troubleshooting Oracle Business Intelligence (XML) Publisher For The Oracle E-Business Suite (Doc ID 364547.1)

  • Can you use 2 sets of bluetooth headphones at the same time with the Ipad 4?

    Hi, I was wondering if anyone could tell me if I can use 2 sets of bluetooth headphones at the same time with the Ipad?
    It is so my children can watch a film or listen to music together.
    Thanks

    No

Maybe you are looking for