Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Compiling Issues

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java Experts and Greenhorns,

Could anyone tell me what is wrong with the following source-code? I've made several reference variables and assigned them each to data-values, but the files will not compile. There is issue with the variables assigned being initiated, but I am unsure why declaring a method would also cause issue.






 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jennifer Swatson wrote:Could anyone tell me what is wrong with the following source-code? I've made several reference variables and assigned them each to data-values, but the files will not compile.



The first thing to do is to read the error messages which the compiler produces. They are intended to tell you what the problem is, but sometimes they are not helpful or hard for beginners to understand.

So it would help if you posted them here, and let us know which lines of code they are referring to.
 
Saloon Keeper
Posts: 10652
227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Paul said, please post stack traces when you have a problem like this.

Having said that, the problem is most likely that you're declaring a method inside the constructor. You can't do that. Finish the constructor and then start the method.
 
Marshal
Posts: 65769
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I start worrying when I see casts. Lines 30‑31. It means you are adding methods to subtypes which I think is called functional extension (as opposed to type extension, but I am not certain). It makes me suspicious because the subtype instances cannot always be used as instances of the supertype without casts. I am not quite sure what the answer is, whether you should move those methods all into the supertype. But it does show one of the difficulties with inheritance.
Remember the cast is error‑prone; if you get the wrong cast or the wrong position, you will suffer an exception. It is actually quite difficult to sort out that sort of design problem.
You would find things easier, I think, if you use an array initialiser:-It has the advantage that you get exactly the right size for your array: no risk of nulls hiding in the arry and no risk of exceeding is maximum index. And where did you find names like Sam Carla and Woody?
        .
 
Rancher
Posts: 4262
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that bit from Campbell also shows a typo in the code...Mmeber?

Campbell Ritchie wrote:And where did you find names like Sam Carla and Woody?
        .



The same place that Diane, Norm and Cliff came from.
 
Campbell Ritchie
Marshal
Posts: 65769
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would never imagine that everybody knows your such names
 
Jennifer Swatson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone thanks for your response,

The errors i've found is an illegal start of expression from the public void payday from the Staff Class and class-enum expected from the same file. The names are made up, i guess Woody would refer to Toy Story 4.
 
Campbell Ritchie
Marshal
Posts: 65769
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jennifer Swatson wrote:. . . illegal start of expression from the public void payday. . .

Most commonly cause by trying to declare a method inside something else, as somebody has already suggested.

class-enum expected from the same file. . . . , i guess Woody would refer to Toy Story 4.

No, they are the drinkers in the Cheers Bar. You are missing Frasier and Lilith.
The class interface or enum expected error has different meanings depending on whether it is at the start or end of the class.
 
lowercase baba
Posts: 12766
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woody, Sam, Carla and Diane worked at the bar. Sam was an alcoholic, so he never drank (liquor).  

Norm, Cliff, Frasier and Lilith were regulars at the bar.
 
Campbell Ritchie
Marshal
Posts: 65769
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

fred rosenberger wrote:Woody, Sam, Carla and Diane worked at the bar. . . . .

Isn't “worked” a bit of an exaggeration  ?
 
Dave Tolls
Rancher
Posts: 4262
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woody, played by Woody Harrelson (Haymitch in the Hunger Games, for the youth amongst you).
Sam, played by Ted Danson ... lots of other things, but maybe CSI for something more recent?
Cliff, played by John Ratzenburger...every Pixar movie ever (he was Hamm in Toy Story, for example).
Carla, Rhea Perlman (aka Mrs Danny DeVito).

Not sure what the others are doing these days.
 
Campbell Ritchie
Marshal
Posts: 65769
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shall we compose compile ourselves and return to the official topic of this thread.
 
permaculture is largely about replacing oil with people. And one tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!