This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Parse a string to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Parse a string to int" Watch "Parse a string to int" New topic
Author

Parse a string to int

S. Stacey
Greenhorn

Joined: Jul 03, 2003
Posts: 20
Hello All,
I am trying to parse a string to an int with the following code:
Integer pa = Integer.parseInt(txtAudio.getText());
When I complie the code I get the following error:

Quote.java:101: incompatible types
found : int
required: java.lang.Integer
Integer pa = Integer.parseInt(txtAudio.getText());
^
I have import the java.lang.Integer class and that did not fix the error.
Thanks for your help
Stacey
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You don't need to import java.lang.Integer, as every class in java.lang is implicitly imported.
The message is telling you that this method returns "int", but you're assigning the result to an Integer. "Integer" is a kind of object, while "int" is a primitive type. You most likely watt to use "int" here instead -- i.e., pa should be an int, not an Integer.
If you really do want pa to be an Integer, then parseInt is the wrong method to call -- use "new Integer(txtAudio.getText())" instead.


[Jess in Action][AskingGoodQuestions]
S. Stacey
Greenhorn

Joined: Jul 03, 2003
Posts: 20
Thanks Ernest that worked....:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parse a string to int
 
Similar Threads
string to int
problem in deleting data
Reg. Integer literals
parse int to string???help!!!!
How to convert string to int ?