Solved

java.net.UnknownHostException: C

Posted on 2004-04-10
9
2,699 Views
Last Modified: 2011-09-20
I am getting java.net.UnknownHostException: C on Windows XP, when trying to open a html document using JEditorPane. Below is the code. Same code works fine on Windows 2000 though.


import java.awt.Dimension ;
import java.awt.Toolkit;

import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JDialog;

import java.net.URL;

import java.io.IOException;


public class TestHelpDoc {


      public static void main(String args[]) {

            try {
                  JEditorPane pane = new JEditorPane("file://C:/userDocs/ui/logonUserDoc.htm");
                  JScrollPane scroller = new JScrollPane();
                  scroller.getViewport().add(pane);
                  JDialog dialog = new JDialog();
                  dialog.getContentPane().add(scroller);
                  dialog.pack();
                    // initialize screen display size location
                  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                  double displayWidth = screenSize.getWidth() - (10 * 2);
                  double displayHeight = screenSize.getHeight() - (60 * 4);
                  dialog.setBounds(10, 60,(int) displayWidth, (int) displayHeight);
                  dialog.setVisible(true);
            }

            catch (Exception e) {
                  e.printStackTrace();
            }


      }
}

and the StackTrace:
java.net.UnknownHostException: C
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:153)
        at java.net.Socket.connect(Socket.java:452)
        at java.net.Socket.connect(Socket.java:402)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
        at sun.net.NetworkClient.openServer(NetworkClient.java:118)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:423)
        at sun.net.ftp.FtpClient.<init>(FtpClient.java:692)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.ja
va:175)
        at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnec
tion.java:257)
        at javax.swing.JEditorPane.getStream(JEditorPane.java:704)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:392)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:775)
        at javax.swing.JEditorPane.<init>(JEditorPane.java:249)
     

Regards,
0
Comment
Question by:allahabad
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 14

Assisted Solution

by:Tommy Braas
Tommy Braas earned 50 total points
ID: 10799613
Change the instantiation of the JEditorPane to (adding another '/'):
 
    JEditorPane pane = new JEditorPane("file:///C:/userDocs/ui/logonUserDoc.htm");
 
0
 
LVL 92

Expert Comment

by:objects
ID: 10799669

 JEditorPane pane = new JEditorPane("file:///C|/userDocs/ui/logonUserDoc.htm");
0
 
LVL 3

Author Comment

by:allahabad
ID: 10799684
Thanks orangehead911 and objects.

Yes, it works on Windows 2000 and XP.

Why is it different for file protocol; URL syntax(protocol://resourseLoation) wise, compare to http or RMI or any other protocol.
 


Regards,
0
 
LVL 92

Expert Comment

by:objects
ID: 10799703
> Why is it different for file protocol

its not.

protocol is "file", host is blank, filename is "C|/userDocs/ui/logonUserDoc.htm"
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:allahabad
ID: 10799771
Hi objects,

It's nice to see your response.

I am still not clear no this.

There is 3 "///" (file:///) for file protocol instead of  2 "//" as we write after the protocol like "http://hostname/file".

So, one extra "/" is to mention host which is blank ?.

Regards,
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 10799778
> There is 3 "///" (file:///) for file protocol instead of  2 "//"

no 2 after the protocol, and one after the (nonexistent) host.

> as we write after the protocol like "http://hostname/file".

if there was no host it would look like:
http:///file

> So, one extra "/" is to mention host which is blank ?

that is correct
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10808653
JEditorPane pane = new JEditorPane("file:/C:/userDocs/ui/logonUserDoc.htm");

should work OK
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10808767
=-)
0
 
LVL 92

Expert Comment

by:objects
ID: 10809073
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now