Solved

java.net.UnknownHostException: C

Posted on 2004-04-10
9
2,853 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

770 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