Results 1 to 16 of 16
  1. #1
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Need help with compiler error

    Code below is straight out of text book. I am using a static method to convert a string to an Integer object. Next using a instance method to convert Integer object to an int.

    Compiler is giving me two "cannot find symbol" errors:
    One pointing to the dot operator between "Integer.valueOf(s)"
    The other pointing to the dot operator between "obj.intValue()"

    I have latest JDK installed: jdk-7u51-windows-x64.exe
    Looks like JCL installed correctly with rt.jar file located in "lib" directory under "Program Files"
    Spent days trying to fix. Any help would be greatly appreciated.

    Following is source code:

    Java Code:
    public class StringToInt
    {
    	public static void main (String args [])
    	{
    		String s = "125";
    		Integer obj = Integer.valueOf(s);
    		int i = obj.intValue();
    		i += 10;
    		System.out.println(i);
    	}
    }
    Last edited by Jake555SK; 03-01-2014 at 02:55 AM.

  2. #2
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Need help with compiler error

    Well I literally just pasted that code into my IDE and it worked with no problems -

    the error you are getting isn't from incorrect code.

    Try this - I have no clue if this'll fix it or not, but it's worth a try.
    Add
    Java Code:
    import java.util.*;
    at the very top of your code and see what happens

  3. #3
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Didn't fix it. Still getting same 2 errors. Thanks for suggestion.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with compiler error

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Thank you

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with compiler error

    The posted code compiles and executes without any errors. It prints: 135
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Thanks for taking a look. I know the code is correct. I am looking for suggestions of why it is compiling on my computer with the errors I stated above.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with compiler error

    Copy the full contents of the command prompt window from when you compile the code and get the error and paste it here.

    Do you have your own version of the Integer class?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Need help with compiler error

    Ok, try running this

    Java Code:
    public class test {
    public static void main ( String[] args ) {
    String s = 199;
    int x = Integer.parseInt(s);
    System.out.println(x);
    }
    }
    Just out of interest, tell me if that works.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with compiler error

    @AlexGraal Did you try compiling that code? What errors do you get with it?

    BTW Why isn't the code properly formatted?

    @Jake555SK Don't pay too much attention to AlexGraal today. His posts aren't useful.
    Last edited by Norm; 03-01-2014 at 04:22 AM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Thanks very much for assistance. I am responding from road and will be back at my computer within 30 mins to post errors and run suggested code.

  12. #12
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Need help with compiler error

    Well Norm I just typed it up. If it is a problem with the Integer class, that shouldn't even compile for him.

    I don't know - maybe I'm going crazy, but that seems like a valid test to run.
    Last edited by AlexGraal; 03-01-2014 at 04:55 AM.

  13. #13
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Quote Originally Posted by Norm View Post
    Copy the full contents of the command prompt window from when you compile the code and get the error and paste it here.


    Following is compiler output:

    C:\Users\Jake\Documents\java>javac StringToInt.java
    StringToInt.java:10: error: cannot find symbol
    Integer obj = Integer.valueOf(s);
    ^
    symbol: method valueOf(String)
    location: class Integer
    StringToInt.java:11: error: cannot find symbol
    int i = obj.intValue();
    ^
    symbol: method intValue()
    location: variable obj of type Integer
    2 errors

    C:\Users\Jake\Documents\java>


    Do you have your own version of the Integer class?
    The only version of the Integer class I have would be in the Java Class Library that came with the JDK. I opened the bytecode in the rt.jar file and found what appeared to be the Integer class. I uninstalled and re-installed the JDK a couple of times to make sure that it wasn't the problem.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with compiler error

    @AlexGraal
    I just typed it up
    But you didn't compile it did you?
    Also what was the recommendation for: import java.util.*; about?

    I guess you are trying, but you could try a little harder to post correct code.


    @Jake555SK Try the code with this change:
    Java Code:
          java.lang.Integer obj = java.lang.Integer.valueOf(s);
    That should mask any local versions of the Integer class.


    Here's an example of how to get the errors you are getting:
    The code:
    Java Code:
    public class StringToInt
    {
        class Integer {}       // false class to cause errors
    
        public static void main (String args [])
        {
            String s = "125";
            Integer obj = Integer.valueOf(s);
            int i = obj.intValue();
            i += 10;
            System.out.println(i);
        }
    }
    Here are the results of
    Java Code:
    Running: D:\Java\jdk1.7.0_45\bin\javac.exe -cp . -Xlint  StringToInt.java
    
    StringToInt.java:8: error: cannot find symbol
            Integer obj = Integer.valueOf(s);
                                 ^
      symbol:   method valueOf(String)
      location: class StringToInt.Integer
    StringToInt.java:9: error: cannot find symbol
            int i = obj.intValue();
                       ^
      symbol:   method intValue()
      location: variable obj of type StringToInt.Integer
    2 errors
    
    2 error(s)
    Last edited by Norm; 03-01-2014 at 05:10 AM.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    When I copied the compiler output in last post the arrows got displaced. The first arrow was pointing at the dot operator between "Integer.valueOf(s)".
    The second arrow was pointing at the the dot operator between "obj.intValue()".

  16. #16
    Jake555SK is offline Member
    Join Date
    Mar 2014
    Posts
    8
    Rep Power
    0

    Default Re: Need help with compiler error

    Quote Originally Posted by Norm View Post
    @AlexGraal
    But you didn't compile it did you?
    Also what was the recommendation for: import java.util.*; about?

    I guess you are trying, but you could try a little harder to post correct code.


    @Jake555SK Try the code with this change:
    Java Code:
          java.lang.Integer obj = java.lang.Integer.valueOf(s);
    That should mask any local versions of the Integer class.


    Here's an example of how to get the errors you are getting:
    The code:
    Java Code:
    public class StringToInt
    {
        class Integer {}       // false class to cause errors
    
        public static void main (String args [])
        {
            String s = "125";
            Integer obj = Integer.valueOf(s);
            int i = obj.intValue();
            i += 10;
            System.out.println(i);
        }
    }
    Here are the results of
    Java Code:
    Running: D:\Java\jdk1.7.0_45\bin\javac.exe -cp . -Xlint  StringToInt.java
    
    StringToInt.java:8: error: cannot find symbol
            Integer obj = Integer.valueOf(s);
                                 ^
      symbol:   method valueOf(String)
      location: class StringToInt.Integer
    StringToInt.java:9: error: cannot find symbol
            int i = obj.intValue();
                       ^
      symbol:   method intValue()
      location: variable obj of type StringToInt.Integer
    2 errors
    
    2 error(s)

    Norm - Thank you very very much! That fixed it. I see what is going on. I had created an Integer class that was interfering. I can't adequately express my appreciation for your assistance.
    Alex - Thanks also for your input.

Similar Threads

  1. Compiler error
    By Nikpatel in forum NetBeans
    Replies: 2
    Last Post: 04-26-2012, 10:39 AM
  2. Compiler Error, Please any help?
    By Liberate in forum New To Java
    Replies: 4
    Last Post: 02-04-2012, 08:19 PM
  3. Compiler error please help
    By ShortIt in forum New To Java
    Replies: 5
    Last Post: 02-16-2011, 12:11 AM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. Compiler Error
    By jeneal in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •