• 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

incompatible type problem for array

 
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,
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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Printing out the array reference is not going to print out the contents.

Look at java.util.Arrays
 
Our first order of business must be this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic