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 2 of 2

Thread: How to convert char to string by using method invocation?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to convert char to string by using method invocation?

    public class MethodCall5
     
    {
     
    	public static void main(String[] args)
     
    	{
     
    		MethodCall5 f = new MethodCall5();
    		char q = f.g("Good");
     
    		System.out.println(q);
     
    	}
     
     
    	public char g(char output)
     
    	{
     
    		return output;
     
    	}
     
    }

    I received an error state that "actual argument String cannot be converted to char by method invocation conversion". How can I fix the error? Thank you..
    Last edited by Akirien; August 25th, 2012 at 11:31 PM.


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: How to convert char to string by using method invocation?

    Hello Akirien!

    The g method's signature indicates that it takes a char parameter. But in your main method you invoke g passing it a String ("Good"). You need to pass it a char parameter to fix the error.
    If you actually want it to take a String parameter then you need to 'say' it in the g's signature.

    Hope it helps.

Similar Threads

  1. Char to String - Gender method.
    By ibby50 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 2nd, 2012, 12:42 PM
  2. Method calls and Invocation
    By Akirien in forum Java Theory & Questions
    Replies: 1
    Last Post: August 24th, 2012, 01:37 PM
  3. string-int-char
    By mdhmdh100 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 25th, 2012, 01:35 PM
  4. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 09:58 AM
  5. Convert CHAR to STRING
    By fh84 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 29th, 2009, 09:21 PM