0

Hey i am a beginner in programming. My code looks like this:

public ChatClient1(String screenName, String hostName) {

        super("Chat"); 

    String host=(args.length<1)?null:args[0];

...and it continues.

The error I am getting when i compile is:

cannot find symbol
symbol: variable args

and its for both the args in the code above.

this.screenName=screenName;

Edited by Dani: Formatting fixed

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rameezh88
0

That's because nowhere in that code do you define args.
Do you have a main method with args as its parameter? That version of artgs is only available inside main. You'll need to copy them to somewhere else to use them in other methods.

0

yea ive got a main program. it looks like this:

public static void main(String[] args)   {
          ChatClient client = new ChatClient(args[0],args[1]);
          //client.listen();
     }

Edited by Dani: Formatting fixed

0

It looks like you are mixing up where to do error checking. To fix this you should move
String host=(args.length<1)?null:args[0];
into main before you create your new ChatClient, and then pass host into the constructor instead of args[0]. But you also need to be careful about the order of your arguments because the constructor lists screenName first and hostName second.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.