• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parse a string to int  RSS feed

 
S. Stacey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
S. Stacey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest that worked....:-)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!