Solved

java.net.UnknownHostException: C

Posted on 2004-04-10
9
2,788 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 80
eclipse formatting 6 74
How to simplify a groovy script that reads a WS because the result being sent back is simpler 1 47
oracle 11g 23 51
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

863 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

26 Experts available now in Live!

Get 1:1 Help Now