Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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.
 
Master Rancher
Posts: 4036
47
  • 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: 64131
215
  • 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: 6685
464
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?
 
Sheriff
Posts: 5924
155
Chrome Eclipse IDE Java Postgres Database Ubuntu 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
Sheriff
Posts: 5924
155
Chrome Eclipse IDE Java Postgres Database Ubuntu 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: 700
10
  • 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: 6685
464
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: 5774
56
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: 5774
56
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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!