aspose file tools*
The moose likes Beginning Java and the fly likes Cannot find symbol parseInt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot find symbol parseInt" Watch "Cannot find symbol parseInt" New topic
Author

Cannot find symbol parseInt

thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117


hey guys,
when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..


on job hunt
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

What is the JDK version that you are using.


Ashwin Sridhar
SCJP | SCWCD | OCA
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
in java folder there is jdk1.6.0_18 and jre6 and jre7
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
Winston Gutkowski wrote:
thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston


in the java documentation i have, it says:
it is a static public memeber of Integer class
parseInt(String s)
Parses the string argument as a signed decimal integer.
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
Ashwin Sridhar wrote:You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.


oh i get it... in java, a string array contains references to the string objects and not the strings themselves so i shud use args[0]??let me try it
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

thejwal pavithran wrote:
Winston Gutkowski wrote:
thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston


in the java documentation i have, it says:
it is a static public memeber of Integer class
parseInt(String s)
Parses the string argument as a signed decimal integer.


But you're not passing it a String. Hence the error.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

thejwal pavithran wrote:
Ashwin Sridhar wrote:You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.


oh i get it... in java, a string array contains references to the string objects and not the strings themselves


No variable ever contains an object in Java. Array variables are not special in that sense. A variable contains a primitive, a reference, or null. A String variable contains a reference to a String object. A String[] variable contains a reference to a String[] object, which in turn contains references to String objects.

so i shud use args[0]??let me try it


If you want to parse the first arg that was passed, yes.
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
so how wud i read ints during run time? like scanf or cin?
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

You could have your numbers passed in as a part of arguements in command line. But it would be passed as String and you could convert it into int as you do.

Assume you call your testClass.java and pass 10 as input in command line.

you will do a ,

This 10 would be passed as a String and would be first element in the array args.

So, you convert into int as ,

Remember if you pass anything other than int and try to convert, you will get a NumberFormatException.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

thejwal pavithran wrote:so how wud i read ints during run time? like scanf or cin?

First: Please UseRealWords (←click). This isn't an SMS message.

Second: There's nothing to stop you from piping input to a Java program. On the other hand, things like scanf() are methods, not programs; and cin is a stream, and it's equivalent in Java is System.in.

Winston
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
Ashwin Sridhar wrote:You could have your numbers passed in as a part of arguements in command line. But it would be passed as String and you could convert it into int as you do.



Sir if i want to write like

System.out.println("PLEASE ENTER YOUR NUMBER ");

Then how will I read the value entered by user into an int variable?i am looking for something like cin or scanf
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

Then you should use System.in . Look this doc
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
Ashwin Sridhar wrote:Then you should use System.in . Look this doc


thank you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

thejwal pavithran wrote:Then how will I read the value entered by user into an int variable?i am looking for something like cin or scanf

Class java.util.Scanner would be good for that. Look at the API documentation for that class - it has an example for exactly what you want to do.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find symbol parseInt
 
Similar Threads
cannot find symbol
Mouseover popup location
cannot find symbol
compile time errors
Head First Java - Chapter 11 - MiniMusicCmdLine Error