• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Interfaces

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an interface I'm trying to write and I have an error I can't interpret. It's on line 25.

The code is as follows:



And the error is

Description Resource Path Location Type
Syntax error on token ";", { expected after this token IBaseNPC.java /ShadowEngineElite/src/gameinterfaces/NPCs line 30 Java Problem



Thanks everyone.
 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's an interface so all of the variables have to be public static final, i.e. constants. So you have to assign a value to that variable.

However... did you really mean to create an interface with all of those constant variables in it? A lot of them seem like things which would be mutable in your game, and so implementing that interface might not be useful.
 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't realize that variables in interfaces had to be public static final. That means I'm going to have to change a lot of interfaces to classes :-(
If I set that String corpse_name to String corpse_name = null still causes an error even though I'm setting it to a value.

Also if I do this:

public class IBaseNPC implements IBase

it still gives me that error on the String
 
Paul Clapham
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks to me like the error message says there's a "{" character expected instead of that semicolon. So there must be something different between what you posted and what you actually have on your computer.

So could I suggest you start with this code:



and add your class-level variable declarations one at a time?

 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the following code still causes an error at that string declaration.



OH that was foolish of me. direct_damage and energy_damage don't have data types. lol
 
Paul Clapham
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bingo! I didn't notice that either -- sometimes the compiler error messages are pretty unhelpful.
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic