• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problematic method call

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the first thing i have told him about
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic