Page 1 of 1

createGame throw NullPointerException

Posted: 14 Jan 2018, 14:27
by KVADRO
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();

Re: createGame throw NullPointerException

Posted: 15 Jan 2018, 09:54
by Lapo
Hi,
the post was moved to the right section (SFS2X Questions).

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

Thanks

Re: createGame throw NullPointerException

Posted: 15 Jan 2018, 17:52
by KVADRO
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)

Re: createGame throw NullPointerException

Posted: 16 Jan 2018, 08:40
by Lapo
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.