NullPointException

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Sooo, I am stuck again...

Here is the server part:
PHP:
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "chat";

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

function login($method_name, $params, $app_data)
{
$nick = $params[0];
$dexist = mysql_query("SELECT * FROM `users` WHERE `nick` = '$nick'");
$num = mysql_num_rows($dexist);
if($num != 0) {
    return "Already logged in or nick already exist";
} else {
mysql_query("INSERT INTO `users` VALUES ('$nick')");
return "Logged in";
}
}

function delete($method_name, $params, $app_data)
{
$nick = $params[0];
$dexist = mysql_query("SELECT * FROM `users` WHERE `nick` = '$nick'");
$num = mysql_num_rows($dexist);
if($num == 0) {
    return "does not exist";
} else {
mysql_query("DELETE FROM `users` WHERE `nick` = '$nick' LIMIT 1");
return "Deleted";
}
}

function users($method_name, $params, $app_data)
{

$dexist = mysql_query("SELECT * FROM `users`")or die(mysql_error());

$u = 0;
while($nick1 = mysql_fetch_array($dexist)){
    $nicks[$u] = $nick1["nick"];
    $u++;
}

return $nicks;
}

function chatadd($method_name, $params, $app_data)
{
$chat = $params[0];
mysql_query("INSERT INTO `chat` VALUES ('$chat')");
return "submitted";
}
/*
* This creates a server and sets a handle for the
* server in the variable $xmlrpc_server
*/
$xmlrpc_server = xmlrpc_server_create();
/*
* xmlrpc_server_register_method() registers a PHP
* function as an XML-RPC method. It takes three
* parameters:
* The first is the handle of a server created with
* xmlrpc_server_create(), the second is the name to
* register the server under (this is what needs to
* be in the <methodName> of a request for this
* method), and the third is the name of the PHP
* function to register.
*/
xmlrpc_server_register_method($xmlrpc_server, "login", "login");
xmlrpc_server_register_method($xmlrpc_server, "delete", "delete");
xmlrpc_server_register_method($xmlrpc_server, "chatadd", "chatadd");
xmlrpc_server_register_method($xmlrpc_server, "users", "users");
/*
* When an XML-RPC request is sent to this script, it
* can be found in the raw post data.
*/
$request_xml = $HTTP_RAW_POST_DATA;
/*
* The xmlrpc_server_call_method() sends a request to
* the server and returns the response XML. In this case,
* it sends the raw post data we got before. It requires
* 3 arguments:
* The first is the handle of a server created with
* xmlrpc_server_create(), the second is a string containing
* an XML-RPC request, and the third is for application data.
* Whatever is passed into the third parameter of this function
* is passed as the third paramater of the PHP function that the
* request is asking for.
*/
$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
// Now we print the response for the client to read.
print $response;
/*
* This method frees the resources for the server specified
* It takes one argument, a handle of a server created with
* xmlrpc_server_create().
*/
xmlrpc_server_destroy($xmlrpc_server);
?>

And the client part (it is here where I get the NullPointExeption): http://pastebin.com/f6c413e52

I am getting:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at xmlrpcclient.clientGUI$2.run(clientGUI.java:220)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Server, result and nick is set before that file is run, so there is no probs with that.

The problem is somewhere here:

Code:
String[] nicks = (String[]) client.execute("users", params);
            for(int i = 0; i < nicks.length;i++){
              nicks1[i] = nicks[i];
            }
or

Code:
for(int i = 0; i < nicks1.length;i++){
                cGui.jTextPane2.setText(nicks1[i]);
                }
I'm n00b, so please help in a way I can understand xD
 
Last edited:

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
BTW, for the users function, you can do this:
PHP:
function users($method_name, $params, $app_data)
{

$dexist = mysql_query("SELECT * FROM `users`")or die(mysql_error());

while($nick1 = mysql_fetch_array($dexist)){
    $nicks[] = $nick1["nick"];
}

return $nicks;
}
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
I got a solution like that I parse the nicks on the server and send a string to the server instead. Seems working somewhat now.
 
Top