Solved

java.net.UnknownHostException: C

Posted on 2004-04-10
9
2,969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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