createGame throw NullPointerException

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

KVADRO
Posts: 7
Joined: 05 Jan 2018, 22:13

createGame throw NullPointerException

Postby KVADRO » 14 Jan 2018, 14:27

Hi!

When i try to create Game room from extension with following settings, SmartFoxServer.getInstance().getAPIManager().getGameApi().createGame throws NullPointerException. Why?

Code: Select all

CreateRoomSettings.RoomExtensionSettings extensionSettings = new CreateRoomSettings.RoomExtensionSettings( "main_extensions", "com.zzt.room.BattleRoomExtension" );

SFSRoomVariable param = new SFSRoomVariable( "game_type", _gameType.getType() );
param.setGlobal( false );
param.setHidden( true );
param.setPersistent( false );

List< RoomVariable > variables = new ArrayList< RoomVariable >();
variables.add( param );

CreateSFSGameSettings roomSettings = new CreateSFSGameSettings();
roomSettings.setAutoRemoveMode( SFSRoomRemoveMode.WHEN_EMPTY );
roomSettings.setDynamic( true );
roomSettings.setGroupId( group );
roomSettings.setGame( true );
roomSettings.setGamePublic( true );
roomSettings.setMaxUsers( 2 );
roomSettings.setLeaveLastJoinedRoom( true );
roomSettings.setMinPlayersToStartGame( 1 );
roomSettings.setRoomVariables( variables );
roomSettings.setExtension( extensionSettings );
//roomSettings.setRoomProperties();
//roomSettings.setRoomSettings();
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: createGame throw NullPointerException

Postby Lapo » 15 Jan 2018, 09:54

Hi,
the post was moved to the right section (SFS2X Questions).

Can you show us the full stack trace of the error?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
KVADRO
Posts: 7
Joined: 05 Jan 2018, 22:13

Re: createGame throw NullPointerException

Postby KVADRO » 15 Jan 2018, 17:52

Sure.

Code: Select all

java.lang.NullPointerException
   at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
   at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
   at com.smartfoxserver.v2.entities.managers.SFSRoomManager.containsRoom(SFSRoomManager.java:469)
   at com.smartfoxserver.v2.entities.managers.SFSRoomManager.validateRoomName(SFSRoomManager.java:700)
   at com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:92)
   at com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:272)
   at com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:733)
   at com.smartfoxserver.v2.api.SFSGameApi.createGame(SFSGameApi.java:147)
   at com.nethertech.zone.StartMatchmakingRequestHandler.performMatchmaking(StartMatchmakingRequestHandler.java:203)
   at com.nethertech.zone.StartMatchmakingRequestHandler.handleClientRequest(StartMatchmakingRequestHandler.java:105)
   at com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:208)
   at com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:174)
   at com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: createGame throw NullPointerException

Postby Lapo » 16 Jan 2018, 08:40

Hi,
you've forgot the name of the Room. A room with no name can't be created, and this particular case the exception is raised because the server attempts to check if another Room with the same name exists, but the name is null.

We'll add a check at the top of the API call with a clear Exception in the next release.

Thanks for the feedback.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 39 guests