0

I am calling a WSDL service from PlaneXML - API reference here https://flightwise.com/documentation/39/PlaneXML_API_Reference.html#AirportInfo

My code:

public static void airportName() throws RemoteException{
    String lax = "LAX";       
    PlaneXMLv1SoapProxy foo = new PlaneXMLv1SoapProxy();
    Airport [] info = foo.airportInfo(lax);
    System.out.println("output 1: " + info);
    System.out.println("output 2: " + info.toString());
    System.out.println("output 3: " + info[0]);
}

My output:

output 1: [Lcom.flightwise.planexml.ws.Airport;@604ed9f0
output 2: [Lcom.flightwise.planexml.ws.Airport;@604ed9f0
test
test
output 3: com.flightwise.planexml.ws.Airport@9117a1a4

Why do I return these memory addresses and not a string? Any ideas what might be causing the "test" output?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Ben Mayo
  • 1,285
  • 2
  • 20
  • 37
  • 2
    Does your class overwrite `toString()`? Probably not. As such, it will use the default implementation of [`Object`](http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--). Ah, and because it's an array you are trying to print at the beginning. Use `Arrays.toString(array)` instead. You'll still have to overwrite `toString()` for your Airport class. – Steffen May 27 '14 at 12:36
  • can you post your class airport ? – jlucidar May 27 '14 at 12:36
  • 1
    This is not memory address, It is full name of class + hash code of that object of same class. – Ankit Sharma May 27 '14 at 12:57

4 Answers4

1

As others have answered, you are:

1- Printing the array itself.
2- Using toString() without an override.
3- Printing an Airport Object.
If you want to print specific things about the Airport, you need to use the properties explicitly. Also, read the documentaion https://flightwise.com/documentation/39/PlaneXML_API_Reference.html#Airport

It reads:

Provides basic information on an airport.

Ident As String
ICAO As String
Location As String
Lat As Double
Lon As Double
Elev As Int32
GMTOffset As Short
DST As Short

Community
  • 1
  • 1
Abdul Fatir
  • 6,159
  • 5
  • 31
  • 58
  • Thanks - how can I pass in the requested property, e.g. Ident? I see now how I'm trying to print the object and not actually telling it what I want to know. – Ben Mayo May 27 '14 at 13:01
  • Can you give me a link to the API. I mean the jar or the zip file you are using. – Abdul Fatir May 27 '14 at 13:58
  • I have the axis2 jar in my build path, but am not certain if it's being called. It is here: 'http://www.java2s.com/Code/Jar/a/Downloadaxis2transporthttp161jar.html'. The API overview is at 'flightwise.com/planeXML_API.html' - it but as you found the documentation I'm sure you've seen that also. – Ben Mayo May 27 '14 at 14:23
  • I wasn't talking about this API. I was talking about the PlaneXML API which has the Airport Class. Do you have the source of Airport class? If not try using info[0].getIdent(); or info[0].Ident; You cannot be sure unless you have the javadoc or the sources. – Abdul Fatir May 27 '14 at 16:50
  • Success - I pass the requested property in as in your instruction above. Thanks very much for your patience and help. – Ben Mayo May 27 '14 at 17:26
  • 1
    @BenMayo You're welcome. We are a community. We need to teach and learn each day. :) – Abdul Fatir May 27 '14 at 17:27
0

If you implement toString() method of Airport object you can see strings on console.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
  • 1
    Only for the third line. The first two lines will execute `toString()` on the Array, not an Airport object. – kasoban May 27 '14 at 12:38
0

toString() doesn't return an address . It returns

getClass().getName() + '@' + Integer.toHexString(hashCode())
TheLostMind
  • 35,966
  • 12
  • 68
  • 104
  • 4
    This should have been a comment. – JonK May 27 '14 at 12:41
  • How can / why should an answer be posted as a comment? – TheLostMind May 27 '14 at 13:17
  • Well the real issue here is that they're calling (implicitly and explicitly) the `toString()` method on an array. This reads as though you're simply correcting the asker's assertion that what they're seeing in the output is a memory address. – JonK May 27 '14 at 13:20
  • @JonK - I answered this part - "Why do I return these memory addresses and not a string?" – TheLostMind May 27 '14 at 13:21
0

Since info is an array of String, that's why the output is [Lcom.flightwise.planexml.ws.Airport;@604ed9f0 and not a String, and if you want to print the toString() (if you have overrided) method of your Airport class, then just do :

System.out.println(info[0].toString()) // you can use any index in place of 0
earthmover
  • 4,395
  • 10
  • 43
  • 74