Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

incompatible type problem for array

 
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
 
Ranch Hand
Posts: 2410
  • 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.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • 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: 2410
  • 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: 2410
  • 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
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic