Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

City cannot be converted to City[]  RSS feed

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, i'm having problem with setting the constructor values which has an array in it please help


When  i try to put in line 37 the ci[j] array in the constructor it says : " incomplete types City cannot be converted to City[]", but logical it makes sense , i put the city array inside a country array , i dont understand why it writes this
error
please help

thank you !
 
Marshal
Posts: 6577
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is very very confusing and hard to read.

On line 37 to Country constructor you are trying to pass singular city ci[j], while I suspect constructor is expecting an array of cities.

Anyway, you have been taught some bad concepts initially probably (for example, naming variables, i.e.: c stands for countries and ci for cities. Why not countries and cities?) that you came up with such code.
I'd delete that and start over. To suggest something, we'd need to know what is the task about in general.
 
Marshal
Posts: 63314
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Names like centerX and centralX are just as confusing. Don't start names with _underscores. I can see another compile‑time error. Line 37. I think Liutauras is right; start from scratch.
 
rian bron
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:This code is very very confusing and hard to read.

On line 37 to Country constructor you are trying to pass singular city ci[j], while I suspect constructor is expecting an array of cities.

Anyway, you have been taught some bad concepts initially probably (for example, naming variables, i.e.: c stands for countries and ci for cities. Why not countries and cities?) that you came up with such code.
I'd delete that and start over. To suggest something, we'd need to know what is the task about in general.



ignore the variable naming  thing, i did it because i didn't have much time , but my question is why it writes me can't  cant not be converted City to City[]?
 
Liutauras Vilda
Marshal
Posts: 6577
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

rian bron wrote:ignore the variable naming  thing, i did it because i didn't have much time


Your saved 13 keystrokes saving your own time caused Your Code Readers who want you to help to waste their time deciphering what those variables mean, so really to ignore the things are difficult, especially if readers are not informed upfront if they are relevant or not. If you want your readers to ignore the parts of the code, simply don't post them.

Please post the declaration of the Country class constructor, so the problem would be more apparent to discuss. But in general I think I've explained what I think the problem is, however, I could be mistaken due to insufficient visibility of the Country class, and in particular its constructor declaration.
 
rian bron
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

rian bron wrote:ignore the variable naming  thing, i did it because i didn't have much time


Your saved 13 keystrokes saving your own time caused Your Code Readers who want you to help to waste their time deciphering what those variables mean, so really to ignore the things are difficult, especially if readers are not informed upfront if they are relevant or not. If you want your readers to ignore the parts of the code, simply don't post them.

Please post the declaration of the Country class constructor, so the problem would be more apparent to discuss. But in general I think I've explained what I think the problem is, however, I could be mistaken due to insufficient visibility of the Country class, and in particular its constructor declaration.





this is the private variables of the country class and the constructor .
 
Liutauras Vilda
Marshal
Posts: 6577
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I was correct in my initial post, the problem I've specified indeed is that for your mentioned error.
 
Campbell Ritchie
Marshal
Posts: 63314
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

rian bron wrote:. . . can't  cant not be converted City to City[]?

Because a City isn't a City[] and a City[] isn't a City full stop

Why is that final int not marked private?
 
Something about .... going for a swim. With this tiny ad ...
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!