0

I created a client object and I want to create an array list that stores the information client objects.

Code location: Client.java

ArrayList<Client> ClientInfo = new ArrayList<Client>();

public ArrayList<Client> getClientInfo() {
    return ClientInfo;
}

Code Location: Client Handling.java

c.setClientId(Client.getClientInfo().size());

    Client.getClientInfo().add(c);

Error at ClientHandling.java:

http://vvcap.net/db/ncilHaCfjUY6JeszCnWJ.png

http://vvcap.net/db/ySzyKvM2qT9mu7pqBCmZ.png

Any ideas?

EDIT: MY CLIENT HANDLING CLASS IS NOT STATIC! That is what I am having a problem with. it is not static, and for some reason it is telling me it is static.

2
  • 3
    I think you really need to read some Java tutorials first. Commented Jan 19, 2013 at 12:02
  • Cool story bro, changed my java skills. Commented Jan 19, 2013 at 12:27

3 Answers 3

2

You use the wrong syntax. In Java class names begin with a uppercase letter, variable names begin with lowercase letter. If you use Client as a variable name and Client is also a class you have a problem because Client.getClientInfo() is a static call because Client is a class.

So your code should look like this:

ArrayList<Client> clientInfo = new ArrayList<Client>();

public ArrayList<Client> getClientInfo() {
    return clientInfo;
}

Code Location: Client Handling.java

c.setClientId(client.getClientInfo().size());

client.getClientInfo().add(c);

And finally, where do you create instances of c and client?

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

Comments

1

getClientInfo() is a non-static method and you are trying to call it from a static method. you need to create an instance of the class where getClientInfo() is in and make a call on that instance.

public static void someMethod() {
Client c=new Client();
c.setClientId(c.getClientInfo().size());
    c.getClientInfo().add(c);
}

1 Comment

When i make the 'ClientInfo' Static, it gives me an error with the return statement. IT IS NOT STATIC, i can past ethe whole code for you to see. If i do ctrl + F, and look for static, i end up with nothing.
0

Client is the class. You must make the getClientInfo() function to be static. And while you're at it, also make the ClientInfo static, too.

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.