Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to int 1

Status
Not open for further replies.

wcj00

Programmer
Aug 12, 2003
10
US
I want to convert a string value containing a number to an int type. However upon compilation I receive the following error "int can not be dereferenced" below is my code.

import java.io.*;
import java.lang.Object;
public class test{
public static void main(String args[])throws NumberFormatException{
String example="123";
int converted;
converted=converted.valueOf(example);
System.out.println(converted);
}//end of main


} //End of class


 
Your variable "converted" is a primitive type,it is NOT a class and and for this reason it can't be referenced in tat way.
To correct syntax could be this..
import java.io.*;
import java.lang.Object;
public class test{
public static void main(String args[])throws NumberFormatException{
String example="123";
int converted=Integer.parseInt(example);
System.out.println(converted);
}//end of main


} //End of class





Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top