?
Solved

java.net.UnknownHostException: C

Posted on 2004-04-10
9
Medium Priority
?
3,147 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 200 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

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