Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

incompatible type problem for array

 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I you change your code in the following it will compile fine.

 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remko's code should work.

Just be sure to include an extra }
[ March 11, 2007: Message edited by: Keith Lynn ]
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Printing out the array reference is not going to print out the contents.

Look at java.util.Arrays
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic