getting error:Object Referance not set to an instance of an object

0 votes

hey ! i am calling the WarpClient.GetInstance ().GetAllRooms (); to get the room ids in the zone request listener .the fuction upto there works well but when the call back is received it showsa me this error:

NullReferenceException: Object reference not set to an instance of an object
AssemblyCSharp.Listener.onGetAllRoomsDone (com.shephertz.app42.gaming.multiplayer.client.events.AllRoomsEvent eventObj) (at Assets/Listener.cs:113)
com.shephertz.app42.gaming.multiplayer.client.WarpClient.GetAllRooms ()
appwarp.Start () (at Assets/appwarp.cs:38)
 
my zone request listener code is as follows:-
public void onGetAllRoomsDone (AllRoomsEvent eventObj)
{
Debug.Log ("rooms");
Log ("onGetAllRoomsDone : " + eventObj.getResult());
Debug.Log ("onGetAllRoomsDone : " + eventObj.getResult());
for(int i=0; i< eventObj.getRoomIds().Length; i++)
{
Log("Room ID : " + eventObj.getRoomIds()[i]);
}
}
 
 Please Help!Thanks in advance.
 
asked Feb 10, 2015 in AppWarp by Mihir Solanki (27 points)
edited Feb 11, 2015 by Mihir Solanki

1 Answer

+1 vote
 
Best answer
Hi,

When there is no rooms available, getRoomIds() retursn null. You need to check if getRoomIds is null or not before using it. This should solve your problem. If the issue still persists please let me know.

Thanks
answered Feb 11, 2015 by Suyash Mohan (900 points)
selected Feb 11, 2015 by Mihir Solanki
You can do something like this
public void onGetAllRoomsDone (AllRoomsEvent eventObj)
{
    Debug.Log ("rooms");
    Debug.Log ("onGetAllRoomsDone : " + eventObj.getResult());
   
    if(eventObj.getRoomIds() != null)
    {
        for(int i=0; i< eventObj.getRoomIds().Length; i++)
        {
            Log("Room ID : " + eventObj.getRoomIds()[i]);
        }
    }
}
the error now disappears but i get ongetallroomsdone as 6 in the log .please help!
also when i add an else case to check it it runs .which means the result is null.but i have 3 rooms running in the developer console
This occurs when you try to call getAllRooms() when you are not connected. Please check connection status. You should call this method once you have got success in onConnectDone
Thanks Suyash Worked perfectly.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...