Reputation: 5671
I have tried to integrate Google Play Game Services with my libGDX project.
I have used this code in MainGame class:
public static PlayServices playServices;
public MainGame(PlayServices playServices)
{
this.playServices = playServices;
}
I put this code in MainMenu class, where I would like to show up login Google's login form after some user interactions.
public static MainGame game;
public MainMenu(MainGame game)
{
this.game = game;
}
When I tried to run app, got following error:
Error:(77, 68) error: constructor MainMenu in class MainMenu cannot be applied to given types; required: MainGame found: no arguments reason: actual and formal argument lists differ in length
Upvotes: 0
Views: 97
Reputation: 871
I guess you are trying to send an instance of PlayServices to your core module from Android module. If this is not the case, please correct me and provide more code because I cannot make anything else out of the information you supplied.
You need to use an interface.
In your core module create an interface. Which has necessary functions like connectToGooglePlayServices(), unlockAchivement() etc. All the things that is exclusive to Android.
public class AndroidLauncher extends AndroidApplication implements ThatInterfaceClass {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGdxGame(this), config);
}
@Override
public void connectToGooglePlayServices() {
//connect to play services here
}
@Override
public void unlockAchivement() {
// unlock achivement etc.
}
}
Important part here is giving this as a parameter to the MyGdxGame
class constructor, and implementing ThatInterfaceClass
.
After this put a parameter in your MyGdxGame class' constructor.
public class MyGdxGame extends ApplicationAdapter {
public void MyGdxGame (ThatInterfaceClass interface) {
this.interface = interface;
}
// create etc... Other functions....
}
Now in order to connect to the google play services or unlock an achivement just call interface.connectToGooglePlayServices()
Here is a link which explains this better.
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
EDIT: It seems the problem is in the code you didn't supply here. Look at this example of how you should creat e a instance of MainMenu class.
MainGame mainGame = new MainGame(playServices);
MainMenu mainMenu = new MainMenu(mainGame);
I believe you are constructing MainMenu class like this:
MainMenu mainMenu = new MainMenu();
As long as you have this constructor:
public MainGame(PlayServices playServices)
{
this.playServices = playServices;
}
You cannot use constructor without PlayServices parameter. But you could erase your contructor or remove the PlayServices parameter and use it like this:
MainMenu mainMenu = new MainMenu();
mainMenu.setPlayServices(playServices);
Here is another question like yours:
"Actual or formal argument lists differs in length"
EDIT 2: Is your MainMenu class in the android module of the core module? If it is not in android module you cannot use PlayServices class (also cannot have an instance). Also don't look for a workaround just use an interface to initiate the connection. As I said in the initial answer.
EDIT 3: FINAL: It could have been easier for both of us if you have told about the tutorial before. The image you sent in the comments says playServices cannot be resolved:
Make sure you didn't type anything wrong.
Make sure the PlayServices interface is in the core module.
Read the tutorial again. Make sure you added libraries, dependencies etc. correctly.
The tutorial tells you to create AndroidLauncher activity. But libGdx creates it by default.
Apart from this I cannot help you further, without sitting on your chair. For your next questions, please supply more information. A lot more.
Upvotes: 1