0

I have method to call getSystem() by passing parameter ipadd, I have two class as mentioned below

SystemReport Class

public class SystemReport
{
    protected System[] system;

    public ComputerSystemResponse ()
    {
    }

    public void setSystems( System[] system )
    {
        this.system = system;
    }

    public System[] getSystem()
    {
        return system;
    }

}

System Class where site details reside which i'm interested in,

public class System 
{

protected String site;

 public System()
  {
  }

  public System(String site)
  {
  this.site=site;
  }

  public void setSite(String site) 
  {
        this.site = site;
  }

    public String getSite() 
    {
        return site;
    }

}

Method in different class & trying to retrieve value of site through looping

SystemReport rep = classInstance.getNames(ipadd);
System[] test = rep.getSystem();

Return type of getNames

protected SystemReport getNames (ipadd)
{
  SystemReport rep = new SystemReport();

  return rep;
}

Answering Questions:
1. classInstance.getNames(ipadd) has return type of SystemReport
2. rep size is > 0

now i would like to get site from rep, I tried checking the length by doing test.length is 0. What am i missing ?

3
  • 1
    What's the problem? WHat code are you executing, what do you expect it to do, and what does it do instead? Commented Apr 9, 2013 at 21:52
  • 1
    what is returned from this: classInstance.getNames(ipadd); Commented Apr 9, 2013 at 21:54
  • 1
    need to look at getNames.. How does it return's SystemReport Commented Apr 9, 2013 at 21:54

2 Answers 2

1

your getNames function returns a new, blank instance of a SystemReport. You call new SystemReport() but the default constructor doesn't add anything to the list, so length would be 0.

You need to call setSystems on your created report and pass in wherever you get your System[] system array.

Sign up to request clarification or add additional context in comments.

Comments

1

I think you need to do this:

SystemReport rep = new SystemReport();
rep.setSystems((classInstance.getNames(ipadd)).getSystem());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.