• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

The type Recyclable is already defined  RSS feed

 
Ranch Hand
Posts: 43
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys I have eclipse error. I research the  error quite some times and got nothing. Can you help me out ?  
This is part of my code.



The interface Recyclable got me error  The Recyclable is already defined.
 
Rancher
Posts: 3797
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means pretty much what it says.
You already have a class called Recyclable somewhere.
 
Marshal
Posts: 62231
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Recyclable a nested type? Do you have something called Recyclable elsewhere?
 
Keit Koppel
Ranch Hand
Posts: 43
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I got this. I deleted the earlier same class name code.  This is offtopic but I got another error . SodaBottle cannot be resolved to type .. This is the static and non-static class thing ?
 
Marshal
Posts: 6363
437
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

You have your braces off. And what has happened with a constructor of Bottle class?
 
Marshal
Posts: 5633
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Keit Koppel wrote:I got another error . SodaBottle cannot be resolved to type .. This is the static and non-static class thing ?


Probably not. It's probably an "I can't find the SodaBottle class anywhere" thing.
 
Keit Koppel
Ranch Hand
Posts: 43
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Keit Koppel wrote:I got another error . SodaBottle cannot be resolved to type .. This is the static and non-static class thing ?


Probably not. It's probably an "I can't find the SodaBottle class anywhere" thing.


I have the SodaBottle class already. This means then the class placing is wrong then ?
 
Knute Snortum
Marshal
Posts: 5633
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a class uses another class, it need to be able to find that class.  For very small projects, putting all the classes in one folder is fine.  When you write bigger projects you're going to want to use package and import statements.  But for now...

Can you post the javac command and which folder you are in when you execute it?
 
Bartender
Posts: 639
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the line of code where the error occurs? Seems suspicious to me to have the error message using ".SodaBottle" (with the dot in it).
 
Keit Koppel
Ranch Hand
Posts: 43
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error occurs in this SodaBottle soda = new SodaBottle(size, name); .


 
Liutauras Vilda
Marshal
Posts: 6363
437
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I’ve never seen main method in interface, that is most likely the problem.

Edit: It isnt an interface, just a class name, sorry. Class name Interfaces is very misleading.
 
Carey Brown
Bartender
Posts: 5301
55
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've been told about: nested classes, proper indentation, and mis-matched braces.

Here's what your code looks like with proper indentation. See a problem here?
 
Carey Brown
Bartender
Posts: 5301
55
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps by temporarily removing class methods and fields it might be more obvious.
See how SodaBottle has been defined to be inside Bottle? That's why the compiler can't find SodaBottle.

If you are thinking that you need to do this for inheritance, as in: a SodaBottle IS-A Bottle, then this is not the way to go about it. If you want inheritance then you need to use the "extends" keyword and not nest the classes.

 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!