Results 1 to 6 of 6
Thread: Compiler error please help
- 02-15-2011, 09:51 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
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);
}
}
- 02-15-2011, 10:08 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
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.
- 02-15-2011, 10:12 PM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
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];
- 02-15-2011, 10:21 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
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.
- 02-15-2011, 10:55 PM #5
If the method is expecting one or more parameters to be passed then yes you MUST pass those parameters.
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.plus this method is also a return method so it should be able to return something.
I'm sorry but this is meaningless to me. Provide code to show what you mean.2) I tried the same code with INT variable and it worked. I have no idea why this would not work.
Yes!3) Can you adjust the program in some ways where it will deliver what I am requesting in the MAIN METHOD.
Will I? No because that is your job not mine or anyone else on this forum.
- 02-15-2011, 11:11 PM #6
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
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
-
Getting contents of error messages from compiler
By Norm in forum EclipseReplies: 2Last Post: 06-02-2010, 02:59 AM -
java compiler error
By arshesander in forum New To JavaReplies: 7Last Post: 02-21-2010, 04:18 AM -
Help Finding Compiler error solution please
By jamesr2b in forum New To JavaReplies: 5Last Post: 04-30-2009, 06:07 AM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
Compiler Error
By jeneal in forum New To JavaReplies: 5Last Post: 12-13-2007, 01:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks