*
The moose likes Java in General and the fly likes incompatible type problem for array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "incompatible type problem for array" Watch "incompatible type problem for array" New topic
Author

incompatible type problem for array

ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
hi everyone,
im currently very frustrated with this same problem that i can crack so any help is greatly appreciated.
i currently have an array of arrays, a 2D array of distances. from this i want to take one of the rows of data from it and store it in another array to perform operations on it.
So far my code for this method is:


the 2d array is edge andi want to row 0 of the values in it to go into my 1d array called ce. Wen i compile the program, i get the error message: incompatible types
found: int[]
required: int
on the return ce; line
Thanks in advance
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The problem here is that you have listed the return type as int, but you are trying to return a reference to an int array.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I you change your code in the following it will compile fine.



Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
thansk remco, but it still gives me the same error. im not great with java, so keith could you explain how i go about making the changes your suggesting.
Thanks again
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Remko's code should work.

Just be sure to include an extra }
[ March 11, 2007: Message edited by: Keith Lynn ]
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
sorry guys, it was my fault, i hadnt ready Remko's solution closely enough. i hadnt put the braces after the public static int on the 1st line. Genuine thanks guys, it was so simple but its been bugging me for hours.
Thanks again
ernest mcdermott
Greenhorn

Joined: Mar 05, 2007
Posts: 28
1 last small problem, it now compiles perfectly however when i run it, it doesnt output the array, any ideas what the problem is??
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Printing out the array reference is not going to print out the contents.

Look at java.util.Arrays
 
wood burning stoves
 
subject: incompatible type problem for array
 
Similar Threads
reference to array element
transparently expanding array
problematic method call
minimum edge and arrays
Help with Printing a 2D Array