0

私は登録フォームを持っており、その場で検証を行っています。ユーザーが電子メール フィールドからフォーカスを切り替えた後、データベースにそのような電子メールが登録されているかどうかを確認し、それについて乾杯したいと考えています。ただし、何をしても、次の行である 585 行目で常に null ポインター例外が発生します。

Log.d("Checking wether this email exists in database", json.toString());

ここにすべてがあります:

class CheckWetherAUserWithSuchEmailExists extends AsyncTask<String, String, String> {

        int success;

        @Override
        protected String doInBackground(String... args) {

            int success;
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                Log.d("Kylie", userEmail);
                params.add(new BasicNameValuePair("user_email", userEmail));

                Log.d("request!", "starting");

                // Posting user data to script
                JSONObject json = jsonParser.makeHttpRequest(CHECK_EMAIL_EXISTS_URL, "POST", params);

                // full json response
                Log.d("Checking wether this email exists in database", json.toString());

                // json success element
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    Log.d("Email exists", json.toString());
                    finish(); //fire up an alarm
                    userWithTheSameEmail = true;
                    return json.getString(TAG_MESSAGE);
                } else if(success == 2) {
                    Log.d("Email doesnt exist", json.getString(TAG_MESSAGE));
                    userWithTheSameEmail = false;
                    return json.getString(TAG_MESSAGE);
                } else {
                    Log.d("Something happened", json.getString(TAG_MESSAGE));
                    userWithTheSameEmail = false;
                    return json.getString(TAG_MESSAGE);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;

        }

json を受け入れる php スクリプトは次のとおりです。

<?php

//load and connect to MySQL database stuff
require("config.inc.php");



if (!empty($_POST)) {
    //gets user's info based off of a username.

    $user_email = mysql_real_escape_string($_POST['user_email'];
    #$user_email_to_query = "\"". $user_email . "\"";
    $query = " 
            SELECT 
                user_email 
            FROM users 
            WHERE 
                user_email = '$user_email'
        ";

    if (mysql_num_rows($row) > 0) {
        $response["success"] = 1;
        $response["message"] = "User with such email exists";
    } else {
        $response["success"] = 2;
        $response["message"] = "User with such email doesnt exist. You can continue registering";   
    }
} else {
    die("Another brick in the wall");
}

構成は次のとおりです。

<?php 

    $username = "asd_asd"; 
    $password = "123123"; 
    $host = "localhost"; 
    $dbname = "asd_asd"; 


    $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); 


    try 
    { 

        $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); 
    } 
    catch(PDOException $ex) 
    { 

        die("Failed to connect to the database: " . $ex->getMessage()); 
    } 

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 


    if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) 
    { 
        function undo_magic_quotes_gpc(&$array) 
        { 
            foreach($array as &$value) 
            { 
                if(is_array($value)) 
                { 
                    undo_magic_quotes_gpc($value); 
                } 
                else 
                { 
                    $value = stripslashes($value); 
                } 
            } 
        } 

        undo_magic_quotes_gpc($_POST); 
        undo_magic_quotes_gpc($_GET); 
        undo_magic_quotes_gpc($_COOKIE); 
    } 


    header('Content-Type: text/html; charset=utf-8'); 
    session_start();

これはテーブルです:

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(30) NOT NULL,
  `user_email` varchar(50) NOT NULL,
  `user_password` varchar(100) NOT NULL,
  `user_sex` varchar(10) NOT NULL,
  `user_avatar` varchar(100) DEFAULT NULL,
  `user_date_registered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_last_seen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `user_points` int(11) NOT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE KEY `user_name` (`user_name`,`user_email`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

これはエラー スタック トレースです。

 D/Kylie(4458): hdhdu@jfjd.com
 D/request!(4458): starting
Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
 threadid=9: thread exiting with uncaught exception (group=0x4001e578)
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
 Caused by: java.lang.NullPointerException
 net.asdasd.activities.Signup$CheckWetherAUserWithSuchEmailExists.doInBackground(Signup.java:585)
at net.asdasd.activities.Signup$CheckWetherAUserWithSuchEmailExists.doInBackground(Signup.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
... 4 more

私が提供することになっている情報が他にある場合は、喜んで提供します。

4

1 に答える 1