Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: please tell me why i'm getting this error

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default please tell me why i'm getting this error

    hello,
    please tell me why i'm getting this error

    D:\javafiles\Exam2.java:8: cannot find symbol
    symbol : method parseInt(char)
    location: class java.lang.Integer
    int cell=Integer.parseInt(shap);
    ^
    D:\javafiles\Exam2.java:17: plot(char,int) in Exam2 cannot be applied to (java.lang.String,int)
    Exam2.plot("1",4);
    ^
    D:\javafiles\Exam2.java:18: plot(char,int) in Exam2 cannot be applied to (java.lang.String,int)
    Exam2.plot("0",4);
    ^
    3 errors

    Process completed.



     
    import  java.lang.*;
    import java.util.*;
     
    public class Exam2
    {
    	public static void plot(char shap, int iter)
    	{
    		int cell=Integer.parseInt(shap);
    		for(int i=0; i<iter;i++)
    			System.out.print(cell+" ");
    	}
     
    	public static void main(String [] args)
    	{
    		for(int i=0; i<4;i++)
    		{
    			Exam2.plot("1",4);
    			Exam2.plot("0",4);
    		}
    	}
    }


  2. #2
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: please tell me why i'm getting this error

    import  java.lang.*;
    import java.util.*;
     
    public class Exam2
    {
        public static void plot(char shap, int iter)
        {
            int cell=Character.digit(shap,10);
            for(int i=0; i<iter;i++)
                System.out.print(cell+" ");
        }
     
        public static void main(String [] args)
        {
            for(int i=0; i<4;i++)
            {
                Exam2.plot('1',4);
                Exam2.plot('0',4);
            }
        }
    }

    you defined "shap" as character type, but you pass in a String. Use single quote for character.
    Integer.parseInt takes in a String (check the API documentation ) , if you want to use a character, you can use Character class digit() method to convert a character to an integer.

  3. The Following User Says Thank You to JavaHater For This Useful Post:

    amr (January 4th, 2011)

  4. #3
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Wink Re: please tell me why i'm getting this error

    OR

    In case if you don't want to get lost in the world of Java API documentation, them simply change the signature of your plot method. Take String instead of a char.

    Change this,

    public static void plot(char shap, int iter)
    to this
    public static void plot(String shap, int iter)
    This will resolve all your errors.

    And one more thing, why have you imported the java.lang package?

    import java.lang.*;
    The lang package comes inbuilt for every java class. We don't need to import it explicitly. There is nothing wrong with it, but why to add lines of code for the things which are already available?

    Hope that helps!

    Goldest
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

  5. The Following User Says Thank You to goldest For This Useful Post:

    amr (January 4th, 2011)

  6. #4
    Member
    Join Date
    Nov 2010
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: please tell me why i'm getting this error

    Thank you very much Mr.JavaHater and Mr.Goldest for your help.
    it works know

  7. #5
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Talking Re: please tell me why i'm getting this error

    You are Welcome!
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.