Results 1 to 7 of 7
  1. #1
    gio123bg is offline Member
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    Default Error running java program using URL

    Hi All,
    If I run this simple java program that I have compiled without errors, I receive these error messages.
    Source program.

    import java.net.*;
    import java.io.*;

    public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
    URL yahoo = new URL("url in internet");
    URLConnection yc = yahoo.openConnection();
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yc.getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
    in.close();
    }
    }

    Error message (command: java URLConnectionReader)
    Exception in thread "main" java.lang.noClassDefFoundError: URLConnectionReader
    caused by: java.lang.ClassNotFoundException: URLConnectionReader
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Unknow n Source)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.misc.Launcher$AppClassLoader.loadClass(Unknow n Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: URLConnectionReader. Program will exit.

    I have installed Java EE 5 SDK Update 7 (with JDK 6u14) and I have set the path=C:\Sun\SDK\jdk\bin and classpath=C:\Sun\SDK\lib;C:\Sun\SDK\lib\javaee.jar

    I receive the same error for all simple program using URL class.

    Thanks in advance for your kind support.
    Regards,

    Giovanni

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    So whats with this line of code?
    Java Code:
    URL yahoo = new URL("url in internet");
    I haven't done URL programming, but something smells like fish... You probably want that line to be something like this:
    Java Code:
    URL yahoo = new URL("http://www.yahoo.com");
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    gio123bg is offline Member
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    Default

    Hi,
    what you have observed is right but I wrote the correct url. The problem occurred when I submitted the post. I have received an error solved in this way.
    Consider to have set a right url.

    Hope to have an help.

    Regards,

    Giovanni

  4. #4
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    7

    Default

    I am sure,The problem you had is related to class path of JRE.
    Make sure you set a right class path of JRE
    Mak
    (Living @ Virtual World)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by gio123bg View Post
    Hi All,
    Could not find the main class: URLConnectionReader. Program will exit.
    This is entirely down to you calling "java" incorrectly.

    How are you running this?

    What package is URLConnectionReader in?

  6. #6
    gio123bg is offline Member
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    Default

    Hi,
    I run the java program using:
    java URLConnectionReader

    I set classpath=C:\Sun\SDK\jdk\jre\lib\rt.jar but the problem is still present.

    Hope in a help.
    Thankds.

    Regards,

    Giovanni

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by gio123bg View Post
    Hi,
    I run the java program using:
    java URLConnectionReader

    I set classpath=C:\Sun\SDK\jdk\jre\lib\rt.jar but the problem is still present.

    Hope in a help.
    Thankds.

    Regards,

    Giovanni
    That's half my questions...what package is URLConnectionReader in, if any?

    Where are you running java in relation to where URLConnectionReader is?

Similar Threads

  1. error running java program
    By bdasilva in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 02:46 AM
  2. Replies: 1
    Last Post: 01-12-2009, 09:59 AM
  3. [SOLVED] opening/running a program from java
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 11-25-2008, 09:12 AM
  4. Replies: 0
    Last Post: 04-04-2008, 03:49 PM
  5. Running java program with arguments in Unix"
    By gvi in forum Advanced Java
    Replies: 2
    Last Post: 11-08-2007, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •