GWT Compiler Error: Missing Interface Methods on Subclass (PlayN HTML)
Asked Answered
S

2

6

Disclaimer: I'm new to GWT/PlayN, so this might be an obvious mistake that I'm making.

When I have a basic (starter) PlayN project, my BlahGame class method implements the Game interface, which requires three methods: init, paint, and update. The starter class looks something like:

public class BlahGame implements Game { 
  public void init() { ... }
  public void paint(float alpha) { ... }
  public void update(float alpha) { ... }
}

I created a BaseGame class to implement game, like so:

public class BaseGame implements Game { 
  public void init() { ... }
  public void paint(float alpha) { ... }
  public void update(float alpha) { ... }
}

My main game class then became a sublass of BaseGame like so:

public class BlahGame extends BaseGame {
  public void init() { ... base.init(); ... }
}

Everything compiles and works from Java. But when I try to GWT-compile the HTML version of my game, I get this error:

com.google.gwt.dev.jjs.InternalCompilerException: Failed to get JNode
    at com.google.gwt.dev.jjs.impl.TypeMap.get(TypeMap.java:140)
    at com.google.gwt.dev.jjs.impl.TypeMap.get(TypeMap.java:71)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.getType(BuildTypeMap.java:730)

...


      [ERROR] <no source info>: public class com.deengames.BaseGame
    extends java.lang.Object
    implements : playn.core.Game
/*   methods   */
public void <init>() 
public void init() 
[unresolved] public void paint(float) 
[unresolved] public void update(float) 
[unresolved] public int updateRate() 

I'm not sure what I'm missing here. Is it that some GWT classes need to be updated? Or is it something else? I had expected the HTML vesrion to compile since the Java version compiles; the signatures of the classes shouldn't change from subclassing.

Edit: I'm using a brand new, boilerplate PlayN project. In the class, if I extend the base class AND implement the interface, it still doesn't compile; only removing the base class extension works.

Sg answered 21/11, 2011 at 2:27 Comment(0)
V
7

This is your problem right here:

  [ERROR] <no source info>: public class com.deengames.BaseGame

You have put code in the top-level package com.deengames. I bet that your GWT module file is also in that same package directory, probably something like com/deengames/MyGame.gwt.xml. The GWT module file has to specify sub-package directories for all code that GWT will see.

When you generate a project using the PlayN Maven archetype, it has this structure:

core/src/main/java/com/foozle/core/Barzle.java
core/src/main/java/com/foozle/resources/images/bg.png
html/src/main/java/com/foozle/Barzle.gwt.xml
html/src/main/java/com/foozle/html/BarzleHtml.java

All of the game code is in the com.foozle.core package and the resources are in the com.foozle.resources package. If you look at the generated Barzle.gwt.xml file you will see:

<module rename-to='barzle'>
  <inherits name='playn.PlayN'/>
  <source path='core'/>
  <source path='html'/>
  <public path="resources" />
  <entry-point class='com.foozle.html.BarzleHtml'/>
</module>

The two <source> lines explicitly add the com.foozle.core and com.foozle.html sub-packages to the GWT project. Anything that is not explicitly listed in this GWT module file will be ignored by GWT. Due to the way GWT specifies these packages, it is not possible to add the top-level package to your GWT project. You cannot use:

<source path=""/>

or:

<source path="."/>

You have to put all of your code in sub-packages that are explicitly enumerated in your GWT module file.

Vachon answered 25/11, 2011 at 17:3 Comment(2)
Bingo. Two follow-up questions: 1) What's a good GWT tutorial for us GWT noobs? and 2) How can I create a new module? (I usually separate some helper/"framework" classes into a separate module)Sg
This page provides a good overview of the anatomy of a GWT project. You won't benefit much from a standard tutorial because you won't use GWT directly in most cases. Creating a module is easy, just create a SomeName.gwt.xml in the source tree that you want available to GWT/PlayN and add <source path="pkg"/> entries for the subpackages to be used by GWT/PlayN. You need to include the .java files (and the .gwt.xml) file if you package said code up as a jar for use by your game.Vachon
L
1

I presume there is an issue with the BlahGame.gwt.xml file inclusions. Make sure all the directories are included in that file, as sources. The structure should be similar to:

<module rename-to='blah'>
  <inherits name='playn.PlayN' />

    <source path='core'/>
    <source path='common'/>
     ... etc ...
    <source path='html'/>

    <public path="resources" />

    <entry-point class='full.namespace.BlahGameHtml' />

</module>

Additionally, your BlahGameHtml.java class should look something like:

public class BlahGameHtml extends HtmlGame
{

    @Override
    public void start()
    {
        HtmlAssetManager assets = HtmlPlatform.register().assetManager();
        assets.setPathPrefix("blah/");
        PlayN.run(new BlahGame());
    }

}
Louth answered 21/11, 2011 at 6:50 Comment(9)
My code is as you say. But it doesn't compile. Even if I add the missing methods to my BlahGame class with the @Override annotation, it doesn't compile. Even implementing the interface AND extending the base class doesn't compile.Sg
In that case, if you can post the code, I can have a quick glance and try running it. If it's not possible, then all I can say is that the GWT compiler can't see BaseClass. Additionally, two things I noticed, you have not implemented the updateRate() method and also it should be super.init() instead of base.init(), but they may not be the issue you have.Louth
Also make sure that the gwt.xml file is on directory above the classes; so that the classes are in subdirectories. That will let you include the source directory name in the 'source' tag in the gwt.xml file. From the error message you have provided, the GWT compiler can't see the aource file for the java class. GWT requires the source inorder to convert the code to javascript. Hope that helps.Louth
Okay, I'll post the code tonight. It's standard boilerplate code, so if you're in a hurry, you can make a new project and see it for yourself -- I'll post a comment when I upload it somewhere.Sg
I've fot an exam in two days, so wont get time to do it from scratch, but if the code is already there then I can have a quick glance :) alright, i'll keep checking for the uploaded code then.Louth
Just wondering if you managed to get this working or if you still want me to have a look at it? I'm free for a couple of days, so I could probably have a look if you want.Louth
if you could take a look, that would be really really appreciated. I've hit a road block on thisSg
By the way, this is generic to extending ANY baseclass for Game.Sg
I guess samskivert's explanation was more clearer than mine. :P I mentioned that in an earlier comment, but it was more like a one line answer (haha) - (Also make sure that the gwt.xml file is on directory above the classes; so that the classes are in subdirectories. That will let you include the source directory name in the 'source' tag in the gwt.xml file.) Anyways, glad you solved it! Cheers! :)Louth

© 2022 - 2024 — McMap. All rights reserved.