Is it possible to return an array of objects from a web service?

I have been trying to do this for a while now, and I have come to the conclusion that it may be impossible. To demonstate what I want to do I enclose a simple java file [1]. I have deployed this with Axis 2 and I enclose the responce [2], it is obciously not wat I want.
Is it porrible to do this? If so, how?
Thanks for any help,
[1]
package org.impress;
public class SampleObject {
     public SampleElement[] noParameters(){
          SampleElement[] retArray = new SampleElement[2];
          retArray[0] = new SampleElement();
          retArray[0].name = "one";
          retArray[0].value = "alpha";
          retArray[1] = new SampleElement();
          retArray[1].name = "two";
          retArray[1].value = "beta";
          return retArray;
     public class SampleElement {
          public String name;
          public String value;
}[2]
<ns:noParametersResponse>
     <ns:return type="org.impress.SampleObject$SampleElement"/>
     <ns:return type="org.impress.SampleObject$SampleElement"/>
</ns:noParametersResponse>

Hi
Can anybody help me with the code of how to return a resultset from a web service. i have put the resultset data's in an object array and tried to return it, but in the client side no data comes ,,, i mean it is printed as null.... and plz tell me where to specify the return type of a object in the wsdl file....
thanks..

Similar Messages

  • Deserialize an array of objects from a web service

    Hi, I'm calling a webservice method which returns an array of
    objects (let's
    say classes called MyClass).
    I now want to define a class in actionscript called MyClass
    which matches
    the properties of the class defined in the web service
    (written in .NET),
    call the webservice method, and then deserialize the result
    in actionscript
    into an array of type MyClass.
    The code I have so far is:
    import mx.services.WebService;
    import mx.services.Log;
    var mylog:Log = new Log(Log.DEBUG);
    myLog.onLog = function(txt) {
    trace(txt);
    var ws:WebService = new WebService(wsc.WSDLURL);
    ws.onLoad = function(wsdl) {
    MyPendingCallObject =
    ws.CallTheWebServiceMethodWhichReturnsAnArrayOfMyClasses();
    MyPendingCallObject.onResult = function(result)
    trace(result);
    // HOW CAN I DESERIALIZE the result parameter into an Array
    of
    MyClass ???
    MyPendingCallObject.onFault = function(fault)
    trace('FAULT! ' + fault.faultCode + "," +
    fault.faultstring);
    // If the WSDL fails to load the onFault event is fired.
    ws.onFault = function(fault) {
    trace(fault.faultstring);
    TIA

    Hi,
    I posted a similar problem some time ago :
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=294&threadid =1221565&enterthread=y
    Do you find any solution to your problem ?
    Fabrice

  • Can i return an Array of Objects from c++ to java ??

    hello all,
    Can i return an Array of Objects from c++ to java ??
    If so how is it possible ??
    regards,
    gautam

    I suggest you look into the JNI, Java Native Interface. The answer is yes.

  • Return a Data Holder Object from WS

    Hi!
    My colleagues at the other end of the office are building Web Services using .NET
    and Visual Studio and I'm trying to beat them with Workshop. Most of the time I win
    but I have one problem, that is returning objects. When I return objects from my
    Web Service I'm forced to format the return XML myself via ECMA script. If I don't
    do that my Web Service returns an empty xml message. The problem is that when calling
    my WS from .NET it returns an XMLNode instead of an object. I would like my method
    to return an object which could be used from .NET without manual conversion from
    XML. Is this possible?
    When I'm calling .NET Web Services which return an object I receive an object automatically
    without manually converting XML to the actual object I want.
    /Jesper

    Hi!
    My colleagues at the other end of the office are building Web Services using .NET
    and Visual Studio and I'm trying to beat them with Workshop. Most of the time I win
    but I have one problem, that is returning objects. When I return objects from my
    Web Service I'm forced to format the return XML myself via ECMA script. If I don't
    do that my Web Service returns an empty xml message. The problem is that when calling
    my WS from .NET it returns an XMLNode instead of an object. I would like my method
    to return an object which could be used from .NET without manual conversion from
    XML. Is this possible?
    When I'm calling .NET Web Services which return an object I receive an object automatically
    without manually converting XML to the actual object I want.
    /Jesper

  • Some data is missing while returning complex datatype from a web service

    Hi
    I am returning a complex data type from a web service. complex data type has a super class and some(not all) values from this super class are not being returned to the client. Strange part is that it giving some fields from super class and some values are not returned.
    I saw the soap response also it does not show any tag for those fields. but while creating a response i am setting some string values to those fields but i am not getting at client side.
    all the serailiastion and deseialization classes where created using ANT tasks and i have checked that all the cedec classes have been created.

    for what it's worth, the same problem was reported by one of our developers, although the string size was considerably smaller (probably less then 1 MB). According to him, soap clients generated from apache tools could connect fine and process the XML records. JDev hung. We simply changed our use case to return smaller results sets, but perhaps you could also generate your clients with WSDL2Java rather then JDev (if it is a truly a bug in JDev SOAP)? Can you add record parameters to the payload, in order to limit the results and scroll between remaining rows?

  • Extracting Array of objects from web service

    After a couple days of head banging I now have a webservice
    call executing and I am trying to extract / create a class from the
    ResultEvent:
    If the xml returned from the web service is:
    <people>
    <person name="Mike" />
    <person name="Dave" />
    </people>
    and the class is:
    class Person
    public var Name:String;
    The result event is:
    private function doResults(result:ResultEvent):void
    // how do I create an array of Person objects from result, I
    would also like to know how to create a typed array something like
    class PersonList if possible. I just need the raw how to loop the
    result and set the values on the class
    Thanks,
    Mike

    Well I wound up with just trial and error until I got it
    working, Im sure this will be improved as I go, but it's enough to
    press on with the app for now, this code is in the result function
    and result is the ResultEvent wich appears to be an array of
    generic objects representing the objects returned by the service.
    This in no way uses FDS and is talking to a simple dotnet / asp.net
    web service.
    // here app is a singleton class for app level data it is
    bindable and is used to update the view which in this example is
    bound to a public var MyObjects which in this case is an
    ArrayCollection, I unbox to MyObject in a custom view control
    for (var s:String in result.result)
    m = new MyObject();
    m.ID = result.result[s].ID;
    m.Name = result.result[s].Name;
    m.Type = result.result[s].Type;
    app.MyObjects.addItem(m);
    It also appears that you should create the WebService one
    time, and store refrences to the methods during app startup, the
    methods are called Operations and it appears you set the result and
    fault events then call send on the operation to get the data.
    // store this in a singleton app class
    var ws:WebService = new WebService();
    ws.wsdl = "
    http://dev.domain.com/WebService.asmx?WSDL";
    ws.addEventListener("result",doResults);
    ws.addEventListener("fault",doFault);
    ws.loadWSDL();
    // this is the operation which is also stored in the
    singleton app class
    var op:AbstractOperation = ws.getOperation("GetModules");
    // elsewere in the app we get the operation refrence setup
    result and fault and call send, then copy the generic object into
    our cutom classes using the first chunk of code above
    op.addEventListener("result",doResults);
    op.addEventListener("fault",doFault);
    op.send();
    I thought I would post this as I could find no such example
    in the offline or online docs, If anyone has a better way or see's
    a problem please post.
    I hope helps others with non FDS service calls and I look
    forward to hearing comments.
    Thanks,
    Mike

  • Oracle ADF Mobile getting array of objects from webservice

    hi,
    i am trying to fetch a certain number of records using a webservice call and then storing in the SQLLite DB in the mobile.
    i understand i can create a data control using the webservice > then?
    my webservice returns an array of objects.
    how can i do that?
    regards,
    ad

    It's fairly easy.
    What I have done is created a WebService Controller (plain java class) which calls the methods (from the WS) programmaticly.
    Example :
    public class WSController {
        private final String WSDataControllerName = "ThisIsTheNameOfMyWebserviceDataControl";
        private List pnames ,ptypes ,params;
        public WSController() {
            super();
        public List getAllActioncodesFromWS()
           //start - WS empty params
            pnames = new ArrayList();
            params = new ArrayList();
            ptypes = new ArrayList();
            pnames.add("findCriteria");
            params.add(null);
            ptypes.add(Object.class);
            pnames.add("findControl");
            params.add(null);
            ptypes.add(Object.class);
            //end - WS empty params
            List actionCodes = new ArrayList();
            try
                GenericType result = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod(WSDataControllerName, null, "findActioncodesView1",pnames, params, ptypes);
                if(result!=null)
                    for (int i = 0; i < result.getAttributeCount(); i++)
                        GenericType row = (GenericType)result.getAttribute(i);
                        Actioncode wd = (Actioncode)GenericTypeBeanSerializationHelper.fromGenericType(Actioncode.class, row);
                        actionCodes.add(wd);
            catch (AdfInvocationException e)
                e.getMessage();
            catch (Exception e)
                e.getMessage();
         return actionCodes;
        }I also defined a Pojo named Actioncode :
    Note that the attribute names are completly the same as the VO from the web service.
    public class Actioncode {
        String Actioncode,Descript1;
        public Actioncode() {
            super();
        public Actioncode(String Actioncode, String Descript1) {
            super();
            this.Actioncode = Actioncode;
            this.Descript1 = Descript1;
        public void setActioncode(String Actioncode) {
            this.Actioncode = Actioncode;
        public String getActioncode() {
            return Actioncode;
        public void setDescript1(String Descript1) {
            this.Descript1 = Descript1;
        public String getDescript1() {
            return Descript1;
    }Since the WS method returns a GenericType, you can 'convert' that object to an POJO.
    Read more about it here :
    http://adf4beginners.blogspot.be/2013/01/adf-mobile-how-to-iterate-over-all-rows.html
    I know the blog post is about iterating over rows in an iterator, but it's just to illustrate how you can work with the GenericType

  • Problem with return a ColdFusion query object from a Java class

    Hi!
    I need to return a ColdFusion query object from a Java class
    using a JDBC result set ( java.sql.ResultSet);
    I have tried to pass my JDBC result set in to the constructor
    of the coldfusion.sql.QueryTable class with this code:
    ColdFusion code
    <cfset pra = createObject("java","QueryUtil").init()>
    <cfset newQuery = CreateObject("java",
    "coldfusion.sql.QueryTable")>
    <cfset newQuery.init( pra.getColdFusionQuery () ) >
    My java class execute a query to db and return QueryTable
    Java code (QueryUtil.java)
    import coldfusion.sql.QueryTable; // (CFusion.jar for class
    QueryTable)
    import com.allaire.cfx //(cfx.jar for class Query used from
    QueryTable)
    public class QueryUtil
    public static coldfusion.sql.QueryTable
    getColdFusionQuery(java.sql.ResultSet rs)
    return new coldfusion.sql.QueryTable(rs);
    but when i run cfm page and coldfusion server tries to
    execute : "<cfset pra =
    createObject("java","QueryUtil").init()>" this error appears:
    Object Instantiation Exception.
    An exception occurred when instantiating a java object. The
    cause of this exception was that: coldfusion/sql/QueryTable.
    If i try to execute QueryUtil.java with Eclipse all it works.
    Also I have tried to return java.sql.ResultSet directly to
    coldfusion.sql.QueryTable.init () with failure.
    Do you know some other solution?

    ok
    i print all my code
    pratica.java execute a query to db and return a querytable
    java class
    import java.util.*;
    import java.sql.*;
    import coldfusion.sql.*;
    public class Pratica {
    private HashMap my;
    private String URI,LOGIN,PWD,DRIVER;
    private Connection conn=null;
    //funzione init
    //riceve due strutture converite in hashmap
    // globals
    // dbprop
    public Pratica(HashMap globals,HashMap dbprop) {
    my = new HashMap();
    my.put("GLOBALS",globals);
    my.put("DBPROP",dbprop);
    URI = "jdbc:sqlserver://it-bra-s0016;databaseName=nmobl";
    LOGIN = "usr_dev";
    PWD = "developer";
    DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    try{
    // Carico il driver JDBC per la connessione con il database
    MySQL
    Class.forName(DRIVER);
    /* Connessione alla base di dati */
    conn=DriverManager.getConnection(URI,LOGIN,PWD);
    if(conn!=null) System.out.println("Connection Successful!");
    } catch (ClassNotFoundException e) {
    // Could not find the database driver
    System.out.print("\ndriver non trovato "+e.getMessage());
    System.out.flush();
    catch (SQLException e) {
    // Could not connect to the database
    System.out.print("\nConnessione fallita "+e.getMessage());
    System.out.flush();
    //funzione search
    //riceve un hash map con i filtri di ricerca
    public QueryTable search(/*HashMap arg*/) {
    ResultSet rs=null;
    Statement stmt=null;
    QueryTable ret=null;
    String query="SELECT * FROM TAN100pratiche";
    try{
    stmt = conn.createStatement();// Creo lo Statement per
    l'esecuzione della query
    rs=stmt.executeQuery(query);
    // while (rs.next()) {
    // System.out.println(rs.getString("descrizione"));
    catch (Exception e) {
    e.printStackTrace();
    try {
    ret = Pratica.RsToQueryTable(rs);
    } catch (SQLException e) {
    e.printStackTrace();
    this.close();
    return(ret);
    // ret=this.RsToQuery(rs);
    // this.close(); //chiude le connessioni,recordset e
    statament
    //retstruct CF vede HashMap come struct
    //METODO DI TEST
    public HashMap retstruct(){
    return(my);
    //conversione resultset to querytable
    private static QueryTable RsToQueryTable(ResultSet rs)
    throws SQLException{
    return new QueryTable(rs);
    //chiura resultset statament e connessione
    private void close(){
    try{
    conn.close();
    conn=null;
    catch (Exception e) {
    e.printStackTrace();
    coldfusion code
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN">
    <html>
    <head>
    <title>Test JDBC CFML Using CFScript</title>
    </head>
    <body>
    <cftry>
    <cfset glb_map =
    createObject("java","java.util.HashMap")>
    <cfset dbprop_map =
    createObject("java","java.util.HashMap")>
    <cfset glb_map.init(glb)> <!---are passed from
    another page--->
    <cfset dbprop_map.init(glb["DBPROP"])>
    <cfset pra =
    createObject("java","Pratica").init(glb_map,dbprop_map)>
    <cfset ourQuery
    =createObject("java","coldfusion.sql.QueryTable").init(pra.search())>
    <cfcatch>
    <h2>Error - info below</h2>
    <cfdump var="#cfcatch#"><cfabort>
    </cfcatch>
    </cftry>
    <h2>Success - statement dumped below</h2>
    <cfdump var="#ourQuery#">
    </body>
    </html>
    error at line <cfset pra =
    createObject("java","Pratica").init(glb_map,dbprop_map)>
    An exception occurred when instantiating a java object. The
    cause of this exception was that: coldfusion/sql/QueryTable.
    -----------------------------------------------------------------------

  • Problem in passing/returning objects over dynamic web service call

    Hi Friends,
    I am beginner in java web service.
    Here is the problem I am facing when I pass/return user defined objects to remote web service method using dynamic we service call.
    The client can call the remote web service method in 2 ways.
    1. By generating client stubs using WSDL file
    - In this case, I am able to pass/return the user defined objects to remote method without any issue only when the server side web services are deployed in any server(jboss)
    - But in java 1.6 & above, the web services can be deployed without server using endpoint. In this case, I am not able to pass/return objects over web service calls.
    2. Without generating client stubs (dynamic web service call)
    - This will establish a connection at run time using the given WSDL file (I have attached the document). I have to form an XML(This will contain API name, arguments) string as input at run time
    - In this case, it allows only string as argument while passing & returning.
    Please let me know if you can help me on this.
    Regards,
    pani

    I'm not sure about your question, but this might help:
    [http://forum.java.sun.com/thread.jspa?threadID=5251188|http://forum.java.sun.com/thread.jspa?threadID=5251188]
    You might also want to read on JAXB.

  • Creating an arrays of objects from a class

    I was wondering does any one know how to create an array of objects from a class?
    I am trying to create an array of objects of a class.
    class name ---> Class objectArray[100] = new Class;
    I cant seem to make a single class but i need to figure out how to create an array of objects.
    I can make a normal class with Class object = new Class

    There are four lines of code in your for-loop that actually do something:
    for(index = 0; index < rooms.length; index++) {
    /*1*/  assignWidth.setWidth(Double.parseDouble(in.readLine()));
    /*2*/  rooms[index] = assignWidth;
    /*3*/  assignLength.setWidth(Double.parseDouble(in.readLine());
    /*4*/  rooms[index] = assignLength;
    }1.) Sets the width of an object, that has been instantiated outside the loop.
    2.) assigns that object to the current position in the array
    3.) Sets the width of a second object that has been instantiated outside the loop
    4.) assigns that other object to the current position in the array
    btw.: I bet you meant "assignLength.setLength(Double.parseDouble(in.readLine());" in line 3 ;)
    Since each position in an array can only hold one value, the first assignment (line 2) is overwritten by the second assignment (line 4)
    When I said "construct a new room-object and assign it to rooms[index]" I meant something like this:
    for(index = 0; index < rooms.length; index++) {
        Room aNewRoom = new Room();
        aNewRoom.setWidth(Double.parseDouble(in.readLine()));
        aNewRoom.setLength(Double.parseDouble(in.readLine());
        rooms[index] = aNewRoom;
    }1.) Constructs a new Object in every iteration of the for-loop. (btw: I don't know what kind of objects you're using, so this needs most likely modification!!)
    2.) set the width of the newly created object
    3.) set the length of the newly created object
    4.) assign the newly created object to the current position in the array
    -T-
    btw. this would do the same:
    for(index = 0; index < rooms.length; index++) {
        rooms[index] = new Room();
        rooms[index].setWidth(Double.parseDouble(in.readLine()));
        rooms[index].setLength(Double.parseDouble(in.readLine());
    }but be sure you understand it. Your teacher most likely wants you to explain it ;)

  • Is it possible to return a figure back to the database from a web service

    I have a REST web service setup that has 4 values
    Is it possible to use a db call to grab these 4 values that can be used in an insert to the database?
    Thanks

    If it were SOAP webservices there are other ways, but a simple REST you could do it like this:
    select httpuritype('http://the.server.com/the_url?the_parameters').getxml()
      from dual
    /That gets you an XMLType object that you can then parse to get the results. For example using the XMLTable() function.
    You can see [url http://dspsd.blogspot.dk/2012/10/find-your-way-with-httpuritype-and.html]an example of this method that I blogged about two days ago ;-)
    Edit: Fixed typo HttpUriTType -> HttpUriType ;-)
    Edit again: Fixed method name getxml()
    Edited by: Kim Berg Hansen on Oct 19, 2012 10:01 AM
    Edited by: Kim Berg Hansen on Oct 19, 2012 10:14 AM

  • Error while returning complex data type in a J2EE web service

    Hello,
    I am implementing J2EE web service which returns array of custom class object.
    I have implemented serializable interface to custom class, and also to session bean.
    But it gives the following error:
    Serializing object [Lcom.ltitl.j2ee.ejb.classes.ProjectDetails;@2a2289 fails. Nested message: XML Serialization Error. Object of Class [com.ltitl.j2ee.ejb.classes.ProjectDetails] does not have property [ObjId] of type [java.lang.Integer]. Check if the right object is passed to the serialization routine..
    As error stated about some property ObjId..I tried including such property in my class. But now it gave exception while deploying stating that ObjId already defined.
    Also I want to return multiple arrays of complex custom classes. i tried using vectors but didnt work. What is the method to return arrays of complex custom classes.
    Please help..
    Abhijeet

    Trying to create a web service that returns a Collection doesn't seem to be possible in Netweaver. The reason for this is that languages other than Java have difficulty in mapping Collections, amongst others, to their own native equivalents.
    There is a discussion on the subject here you may find useful:
    http://forum.capescience.com/showthreaded.php?Cat=&Board=webservices&Number=147&page=0&view=collapsed&sb=5&o=&vc=1
    The short answer is to use object Arrays instead, or a custom class that contains an array of each type of object you would expect to find in your Vector
    Hope this helps
    Steve

  • Return multiple values from a Web Service

    Hi,
    I'm learning JAX-WS web services and I'm wondering, how do I return multiple data like, say multiple rows from a table through a web service? I understand that I can use Holders, but those are for JAX-RPC if I'm not mistaken, and I'd like to know the alternative for JAX-WS(if there is any).
    Any help would be much appreciated.

    Debojit Sinha wrote:
    A greeting service where the client types a string(preferably a name), and the service returns "Hello, " followed by that name. I faced the error with returning objects when I tried to return the results of a query with a set of serialized JavaBeans passed into an arraylist. I don't have the complete error log with me now, but the error was generated when deploying with JDeveloper 11g, and it was something about JAXB content model error. Also, There was an error regarding javax.naming.Name saying that JAXB couldn't handle interfaces.yes, you can't return any interfaces. so, instead of returning a List, you have to return an ArrayList. if you use xjc to generate types from a schema, then it will normally generate a "wrapper" class around any collections (which will in turn hold a List).

  • Problem in fetching values from Java Web Service returning ArrayList

    Hi all,
    I am calling an External Java web Service from BPEL. That Java Web Service is returning an Arraylist.
    I am not able to assign the values returned by the Java web service to local String Variables of BPEL.
    Kindly help me...

    Hi,
    My problem has been resolved..
    I have used
    bpws:getVariableData('Invoke_1_useSSH_OutputVariable','parameters',concat('/ns7:useSSHResponseElement/ns7:result/ns8:item\[',bpws:getVariableData('count'),']'))
    where count is the local int variable which contains the index value of the arraylist i.e. which index element we want to retrieve from arraylist.
    Thanks....
    Edited by: user643533 on Sep 12, 2008 12:10 AM

  • Reading an Array of Objects from a .bin file!

    Hey, at the moment I'm creating a program whereby I write a set of objects onto a bin file, in this case an array of objects with a String name/county, and int population/area.... I'm not trying to read it back from the bin file and encountering trouble! I've managed to get it working using plain objects, however I want to be able to read in arrays of objects. The file itself compiles, however during running I get this error
    java.lang.NullPointerException
    at RecordFiles.CoastalRead.main(CoastalRead.java:33)
    at RecordFiles.__SHELL16.run(__SHELL16.java:6)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:774)
    Here is the program itself,
    import java.io.*;
    public class CoastalRead {
        public static void main(String[] args) {
            CoastalTowns towns[] = new CoastalTowns[50];
              towns[0] = new CoastalTowns();
              towns[1] = new CoastalTowns();
              towns[2] = new CoastalTowns();
              towns[3] = new CoastalTowns();
              towns[4] = new CoastalTowns();
              String name, county;
              int population, area;
            try {
                FileInputStream fileIn =
                        new FileInputStream("CoastalTownsBin.bin");
                ObjectInputStream in = new ObjectInputStream(fileIn);
                for (int i = 0; i < towns.length; i++){
                 towns[i] =(CoastalTowns) in.readObject();
                   System.out.println("Deserialized File...");
                       System.out.println("Name: " + towns.name);
              System.out.println("County: " + towns[i].county);
         System.out.println("Population: " + towns[i].population);
              System.out.println("Area: " + towns[i].area);
    in.close();
    fileIn.close();
    } catch (IOException i) {}
    catch (ClassNotFoundException c) {}
    +I'd appreciate a fast reply!+ And if someone needs the writing class I've used, I can post it asap.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    CoastalTowns towns[] = new CoastalTowns[50];
    towns[0] = new CoastalTowns();
    towns[1] = new CoastalTowns();
    towns[2] = new CoastalTowns();
    towns[3] = new CoastalTowns();
    towns[4] = new CoastalTowns();Why create an array with a size of 50 and then only fill 5 elements?
    Why bother filling any elements at all when you are reading the objects from a file?
    What happens if there are less than 50 objects in your file?
    I will assume CoastalTowns holds info about a single town, so why is it pluralised? Do you have a class called Dog or Dogs, Chair or Chairs, Person or People?
    } catch (IOException i) {}
    catch (ClassNotFoundException c) {}DO NOT swallow exceptions. At the very least put in a call to printStackTrace so you know if/when an exception occurs.
    I'd appreciate a fast reply!I typed as fast as I could but unfortunately I'm still and hunt and peck guy.

Maybe you are looking for