Results 1 to 6 of 6
  1. #1
    ShortIt is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Exclamation Compiler error please help

    class Returnall
    {
    //variables
    static char T = '*'; //this is just created to pass down to the method below

    /*Mainly my full progam does not just consist of just two
    methods as shown below, but there is something that I am trying to do that is not
    working for me. I hope someone can help me out and point me to the right direction.

    -I want another method in THIS class to pass a character to another method to another
    method. i.e. sea() ----> yo().

    - once that character is passed to the second method it should return that character to the (MAIN METHOD in <RETURN CLASS>)

    - once returned I should be able to pass that value to another char Variable.

    - I have written the whole code for it and at the end it gives this weird error which I have no idea what to make of it.

    - Please dont mind the funny names*/



    public static void sea()
    {
    reject(T);


    }
    ////////////////////////////////////////////
    //the reason the name of the method is reject is becasue I want this method to spit back
    //out the value to the MAIN METHOD in <RETURN CLASS>.

    public static char reject(char e)
    {
    char Final1;

    return Final1 = e;

    }
    ////////////////////////////////////////////

    /*This is the weird message that I get.
    Return.java:14: reject(char) in Returnall cannot be applied to ()
    result = ALL.reject();

    ^
    */


    }

    ----------------------------------------------------------------------


    class Return
    {
    public static void main(String [] args)
    {
    //variables

    char times = '*';
    char result;

    //new object
    Returnall ALL = new Returnall();


    result = ALL.reject();


    //Just to test to see if the value did get return after
    //the method was called
    System.out.println(result);

    }

    }

  2. #2
    ShortIt is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    Above message is in java so you can copy and paste into two different classes and run it. Saves you time from figuring out the whole code. Any help would be appreciated.

  3. #3
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    Your method reject expects to have some char passed in
    Java Code:
    public static char reject([B]char e[/B])

    and you did not provide it with any char
    Java Code:
    result = ALL.[I]reject()[/I];

  4. #4
    ShortIt is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    1) Is passing an argument necessary all the time? plus this method is also a return method so it should be able to return something.

    2) I tried the same code with INT variable and it worked. I have no idea why this would not work.

    3) Can you adjust the program in some ways where it will deliver what I am requesting in the MAIN METHOD.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,760
    Rep Power
    7

    Default

    Quote Originally Posted by ShortIt View Post
    1) Is passing an argument necessary all the time?
    If the method is expecting one or more parameters to be passed then yes you MUST pass those parameters.

    plus this method is also a return method so it should be able to return something.
    Correct but what gets returned must match the return type in the method header. If it is void then you cannot return anything. If it is int then you cannot return a char, boolean, String etc, it must be an int.

    2) I tried the same code with INT variable and it worked. I have no idea why this would not work.
    I'm sorry but this is meaningless to me. Provide code to show what you mean.

    3) Can you adjust the program in some ways where it will deliver what I am requesting in the MAIN METHOD.
    Yes!

    Will I? No because that is your job not mine or anyone else on this forum.

  6. #6
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    In case you need different usage you can make more methods:
    Java Code:
    public char reject(){
       // some code that returns [I]char[/I]
    }
    public char reject(char c){
        // some code that returns [I]char[/I]
    }
    public char reject(Object o){ [I]// something that is appropriate for your app[/I]
        // some code
    }

    So now you can use
    Java Code:
    result = All.reject();
    
    or
    
    result = All.reject("*");
    
    or something else

    Your class Return looks ok except for
    Java Code:
    result = ALL.reject(); // need argument

    Provide some argument and try again.

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2010, 02:59 AM
  2. java compiler error
    By arshesander in forum New To Java
    Replies: 7
    Last Post: 02-21-2010, 04:18 AM
  3. Help Finding Compiler error solution please
    By jamesr2b in forum New To Java
    Replies: 5
    Last Post: 04-30-2009, 06:07 AM
  4. Replies: 3
    Last Post: 01-23-2009, 08:53 AM
  5. Compiler Error
    By jeneal in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 01: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
  •