aspose file tools*
The moose likes Java in General and the fly likes problematic method call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problematic method call" Watch "problematic method call" New topic
Author

problematic method call

ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
hi everyone,
iv currently got this method for calculating the minimum value in my array.

Iv tried to call it from another class using method call

but i keep getting the error saying:
getMinEdge(int[]) in Prim cannot be applied to ()

can any1 suggest a method call that will work.
Thaks in advance
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Did you pass an array of int[] ??? I can't see that in your method call.

Also wrap the calling code inside a try{} catch(Exception e){} block.

Let me know what happens with you ...

Good luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
thanks Vassili, i did mean to include the [] in the method call, altho even after that im still getting the same error message.
also, im not great with java yet, could you expand on what you mean with the try catch block.
Many thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Why are you declaring an exception in the first place? I can't see any code which would throw an exception. Nor can I see any need for a try . . . catch.

How are you invoking this method? Are you passing "Prim.getMinEdge();" ? You need to pass the name of the array.
Not getMinEdge() and not getMinEdge(myArray[]); You said you require an int[] array as a parameter, then you have to pass an array.

. . . and write "int[] myArray" not "int myArray[]". That way it is easier to see you are dealing with arrays when you look at the code.
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Hello,

As long as you have declared your method as it throws Exception, you must enclose the invoking method in a try ... catch block, because the compiler will expect for this method that it may throw an Exception or any kind of its subtypes at runtime. moreover, even if you catch any thrown Exceptions by this method by using a try ... catch inside the method itself, you still have to enclose the invoking method in a try ... catch.

You can still declare the invoking method that it also throws Exception and in this case you are free to enclose the invoking method statement in a try ... catch block, but you have to enclose the first statement in a try ... catch or declare it as it throws Exception or any of its subtypes.

This technique is called "Declare or Handle"

Study this example, try to edit it according to the explanation above, to see what the complier will do for each case you edit.



For more details about Exceptions, please read this tutorial from SUN.

Best of luck my friend ...
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
As Campbell has already stated, the whole topic of exception handling, while important, is completely orthagonal to the OP's problem.

but i keep getting the error saying:
getMinEdge(int[]) in Prim cannot be applied to ()


The compiler is telling you that you are trying to call a method that expects an int[] parameter, with no parameter at all, which results in a compiler error.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
This is the first thing i have told him about
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
thanks everyone for your help,
firstly it was my fault i had no need for the exception test to be in there so iv removed it.
Also, some of the comments i havent completely understood, this is to be fair my own lack of knowledge of java so please dont think im being insulting for asking for further help. Iv read the comments and worked on my code but im still having no luck, my code is now as follows:

and my method call reads:

int me = p.getMinEdge(ce);

Im trying to get this method to sort my array to find the smallest in it and then simply return the value of this.
However with this code i get two errors, one in each class. in the class with the method, i get the error:
missing return statement with the arrow under the last brace

and in the other class:
incompatible types
found: int
required: int[]
under the 1st curly bracket in the getMinEdge(ce);

i appreciate all the help given so far and please continue to help, this problem is really frustrating me
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
It is confusing to read your code because you aren't using a consistent indentation policy. Find a consistent style guide, like this one, and note which indentation policy they recommend. I think that is probably the best, even though the Java tutorial uses another convention.

When you get your code correctly indented, you will be able to see where the variable "me" is, namely inside the for loop. You have to move it outside the loop, and put its declaration and initialisation outside the loop too.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

In the calling code, ce isn't an array of ints, but a single int.
This is a way to construct an int-array of a single int on the fly:


http://home.arcor.de/hirnstrom/bewerbung
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
thanks Campbell and Stefan, the method itself is working fine now.
Im still having problems with the method call tho, it still says incompatible types
found: int[]
required: int
and it points to the c in {ce}); at the end of the method call.
i really am sorry to keep asking but this is just bugging me so badly
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
me....again.
Iv haenet been to sleep in about 30hours now working on this little problem and iv finally finished it. i say i have, but i owe most of it to everyone who helped on here. Thanks every1 for all your help, it was greatly appreciated.
Ernest.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Well done. Only too pleased to be able to help. What did you do to get it all to work?
[ March 14, 2007: Message edited by: Campbell Ritchie ]
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
as you suggested Campbell i moved the "me" declarations etc to outside of the for loop and that worked fine. the only problem then was the method call. i used Stefans advice and then when it returned the error, i just had to remove the new itn [] from the method call.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problematic method call