• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 3631
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: 60163
188
  • 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: 6015
415
BSD
  • 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: 5130
138
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
Sheriff
Posts: 5130
138
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: 620
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: 6015
415
BSD
  • 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.
 
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:@OP
You have your braces off.

 
Carey Brown
Saloon Keeper
Posts: 4787
52
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
Saloon Keeper
Posts: 4787
52
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!