File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Debugging problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Debugging problem" Watch "Debugging problem" New topic
Author

Debugging problem

Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
Hello, I'm trying to resolve this error for the variable "var". I'm trying to have the user type in a port number while executing the program.
For instance
java myprogram 1986

1986 will be the port number that the user specifies.
I keep getting an error for my code below that states
"var cannot be resolved to a variable"


Can someone show me the code of how to do this?




fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

because you declared it inside the if-block. as soon as you hit the close curly brace, it falls out of scope, and thus doesn't exist on line 9 anymore. You should do this:



one other thing...if var is going to hold an integer value (like a port number), a 'float' is probably not the best choice.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
Oh really? I've changed it to int. Why is float a bad decision by the way? Thanks for your help!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Float is used to represent real numbers (not just integers) with low precision. Did you expect people to ask to use port 2.275?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

You should choose something that best represents what you are trying to do. You can't have a fractional port - it has to be an integer. Therefore, choosing an integer type makes more sense.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Debugging problem
 
Similar Threads
UDP Datagram Connection
Simple problem in running a Server class
Writing a class that receive and broadcast at the same time
Gloal Variables in Java
Responses from UDP Server