Solved

Making an URLConnection

Posted on 1998-05-18
8
567 Views
Last Modified: 2008-02-01
I don't understand why the call to getResponseCode() below gives an UnsatisfiedLinkError.

          URL url = new URL(docName);
          HttpURLConnection checkURL =  (HttpURLConnection)url.openConnection();
          try {
            if (checkURL.getResponseCode() == 404)
            {
              System.err.println("Failed to get doc " + docName);
              return;
            }
          } catch (UnsatisfiedLinkError ule) {
            System.err.println("Unable to resolve docname " + docName);
            return;
          } catch (NullPointerException npe) {
            System.err.println("Can't get doc " + docName);
            return;
          }

If I understand the docs correctly, openConnection() should call connect() for me.
The other weird thing is that this code ran fine under 1.1.2, but fails under 1.1.3 and later.
0
Comment
Question by:wex
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221165
Is it possible that you have multiple JDK  installations on your machine with environment variables pointing to the more than one at a time. For example your CLASSPATH may point to JDK1.1.2\lib\classes.zip while your PATH may contain JDK1.1.3\bin directory. That may cause the described behaviour. (The DLL on your path does not contain the exact native function the JVM is trying to invoke).
0
 
LVL 1

Author Comment

by:wex
ID: 1221166
Yeah, I think that's the right track, but I'm confused why it's happening.  I'm on a UNIX box
and the only relevant thing on my PATH is /usr/java/bin

My CLASSPATH includes only the directories relevant to my project; I'm depending on
java to add the proper directories for its own .class files.  Is that an error?
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221167
It's hard for me to speak about UNIX since I do my development on NT. Each JDK come with set of class files and set of executables and dynamic libraries (shared objects in UNIX). When I install subsequent versions of JDK I install them in different directories which causes my to update CLASSPATH and PATH each time I do that. What you are saying is that your path keeps pointing to /usr/java/bin. Does it mean that each new installation overwrites an older one? Is it the only possible way to install JDK?

Anyway, why don't you find out for sure where the classes.zip and the executables (such as java) for the version you want to use are. You can do it by using "which java" command and renaming directories where class libraries are.

Not putting classes.zip on a classpath is not an error as long as you know that it uses the right version. In your case you don't seem to be sure of that.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:wex
ID: 1221168
There's no classes.zip file in there.  I've checked for it.
I've also checked for the possibility of multiple installations and there's only one on each machine.
The executables are clearly in /usr/java/bin
I checked that and it's the standard approach where everything points to one java_wrapper script which (among a zillion other things) sets the CLASSPATH.

What baffles me is why there's only one file which it can't find.  When I get the stack trace from this error, it looks like this:
java.lang.UnsatisfiedLinkError: getInetFamily
        at java.net.InetAddress.<init>(InetAddress.java:63)
        at
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:201)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:219)
        at sun.net.www.http.HttpClient.New(HttpClient.java:230)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:326)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:407)
        at Footprints.database.convert.ReadPath.parse(ReadPath.java:329)
        at Footprints.database.convert.ReadPath.main(ReadPath.java:896)

So it only fails on finding something in java.net.InetFamily (InetAddress).  If the other .class files are found, why not this particular one?

I'm still baffled.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221169
What OS are you using?
0
 
LVL 1

Author Comment

by:wex
ID: 1221170
I'm using IRIX 6.1 as it happens, but you were essentially correct.
It's a CLASSPATH problem.  I can't figure out how to go back and give you the points.
I guess if you post a new answer I can accept it and you'll get the points that way?
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1221171
Thess are the commands I found in the .java_wrapper script in /usr/java/bin on an our IRIX machine:

COMM_CLASSPATH="$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dev.jar:$JAVA_HOME/lib/i18n.jar:$JAVA_HOME/lib/tiny.jar:$JAVA_HOME/classes"
if [ -z "${CLASSPATH}" ] ; then
    CLASSPATH=$COMM_CLASSPATH
else
    CLASSPATH="$CLASSPATH:$COMM_CLASSPATH"
fi

Thus, CLASSPATH is being set to something very concrete.

Did you fix the problem or you are still looking?
0
 
LVL 1

Author Comment

by:wex
ID: 1221172
OK, the problem was indeed with my $CLASSPATH
36 hours of wild-goose chasing later I've finally gotten it working.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HSSFWorkbook cannot be resolved error 10 72
replace a word with other 1 44
how to install java on RHEL image on EC2 4 30
printf performancy 11 43
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

831 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