I am looking over the RPG character example and was trying to do an addRequestHandler. In flash I have it send over the proper parameters when the player logs in correctly. Problem is I receive a NULL pointer error due to the
sfs.send(new ExtensionRequest("getModel", new SFSObject()));
I am apparently sending a Null object so it is not allowing the request handler to proceed. This is from the example for the RPGcharacter as mentioned before.
What is going wrong exactly? I am trying to get data from the server and the server won't let me through this send request. I placed traces in the server extension code and noticed the Request handler did not get used at all so I know it isn't server side.
If you're getting a nullexception in that snippet, then chances are good your variable sfs is not pointing at anything. Make sure its referencing the SmartFoxServer object you used to connect with.
Thanks for your help again but neither of those two fixed the issue.
My sfs is working fine and I even did an ip check and a connected check before I send the extension request. Both came back as connected and with the propery ip. Also changing to the params instead of what I had did not do the trick either. Same issue.
What is strange is the login request works fine where I even put in a username and password which checks the database and does work. Then inside of the onLogin function I send my extensionrequest. What I receive everytime I do this is the following response:
Edit:
Also I found this error before the error below:
ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1]Controllers.ExtensionController -
End Edit
Exception: java.lang.NULLPointerException
Message: ******NULL******
Description: Error while handling client request in extension: ....
Extension Command: getModel
Then there is just a bunch of things in the Stack Trace.
package cw.extensions;
import com.smartfoxserver.v2.annotations.Instantiation;
import com.smartfoxserver.v2.annotations.Instantiation.InstantiationMode;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
@Instantiation(InstantiationMode.SINGLE_INSTANCE)
public class CWGetInfoHandler extends BaseClientRequestHandler
{
private ISFSObject model;
private WarehouseInfo[] warehouse;
public CWGetInfoHandler()
{
trace("INSIDE CWGETINFOHANDLER");
this.model = generateModel();
}
@Override
public void handleClientRequest(User sender, ISFSObject params)
{
trace("Sending model to requester: " + sender);
// We just send the data model as SFSObject
send("getModel", model, sender);
}
/*
* Generate the data model
*/
private ISFSObject generateModel()
{
trace("GENERATING MODEL!!");
CWMain ext = (CWMain) getParentExtension();
warehouse = ext.getWarehouse();
// --- Prepare SFSOBJECT --------------------------------------------------------------------
ISFSObject sfsObj = SFSObject.newInstance();
sfsObj = warehouse[0].toSFSObject();
trace("ABOUT TO RETURN THE SFSOBJECT FOR SENDING");
return sfsObj;
}
}
warehouse is actually an array of a class but I am just specifically grabbing the first part of the array so that I can see it work before I make it do what I actually want.
public ISFSObject toSFSObject()
{
ISFSObject sfso = new SFSObject();
sfso.putInt("id", id);
sfso.putInt("owner_id", owner_id);
return sfso;
}
Problem is with all the trace commands I have in the requesthandler none show up in my server log, so I don't believe the requesthandler is even going to that point. Even the constructor isn't showing the trace.
I appreciate your help on this, it is driving me nuts.
Seems I run into a slight issue after testing some things out. First I cannot put a trace command inside the function generate model, it causes the NULL exception error. Next I cannot put
Ok now I realize its because the constructor was causing the issue. I moved the function generate model out of the constructor and had it set model inside the handlerequest and it works.