3

Android アプリを開発していますが、実際のデバイスでアプリを実行すると問題が発生します。エミュレーターでは、すべてが正常に動作します。アクティビティが開始したら、ユーザー名とパスワードを入力し、ログイン ボタンを押します。何も起こらず、2 ~ 3 分後に以下のエラーが表示されます。

これは LogInActivity.java です

package com.example.movenialapplication;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LogInActivity extends Activity{

IpString ipStr = new IpString();
static String ip = IpString.ipAdress;
private static String url_logIn = "http://"+ip+"/android_nydor/login3.php";
Button btnForLogIn;
JSONParser jsonParser = new JSONParser();
String username,password;
EditText usernameTxt;
EditText passwordTxt;

private static final String TAG_SUCCESS = "success";
private static final String TAG_USERS = "users";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.log_in);
    btnForLogIn = (Button) findViewById(R.id.LogInButton);
    btnForLogIn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            usernameTxt =(EditText) findViewById(R.id.username);
            passwordTxt =(EditText) findViewById(R.id.password);
            username = usernameTxt.getText().toString();
            password = passwordTxt.getText().toString();
            int success;
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("username", username));
                params.add(new BasicNameValuePair("password", password));
                // getting product details by making HTTP request
                // Note that product details url will use GET request

                //StrictMode.ThreadPolicy policy = new  StrictMode.ThreadPolicy.Builder().permitAll().build();
                //StrictMode.setThreadPolicy(policy); 

                JSONObject json = jsonParser.makeHttpRequest(url_logIn, "GET", params);
                //Log.i("jsonOb", json.toString());

                // json success tag
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(),
                            AllFromMovenialActivity.class);
                    // sending pid to next activity
                    //in.putExtra(TAG_ID, movenialID);

                    // starting new activity and expecting some response back
                    startActivityForResult(in, 100);
                }
                else{
                    usernameTxt.setText("") ;
                    passwordTxt.setText("") ;
                    TextView t = (TextView)findViewById(R.id.WrongPassword);
                    t.setVisibility(View.VISIBLE);
                }
            }
            catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

}

ここにphpコードがあります:

<?php
//opening connection link
$link_fetch_data = mysql_connect('localhost:3306', 'root', 'pass');

$username=$_GET['username'];
$password=$_GET['password'];

if (!$link_fetch_data) {
    die('Could not connect: ' . mysql_error());
}
//selecting db from server
mysql_select_db("sccm_nydor", $link_fetch_data);

$q=mysql_query("SELECT idusers FROM users WHERE username='".$_GET['username']."' AND password = SHA1(CONCAT('".$_GET['username']."','".$_GET['password']."')) AND active=1");

if (!empty($q)) {
        // check for empty result
        if (mysql_num_rows($q) > 0) {

            $q = mysql_fetch_array($q);

            $movenial_users = array();

            $movenial_users["idusers"]=$q["idusers"];

            // success
            $response["success"] = 1;

            // user node
            $response["movenial_users"] = array();

            array_push($response["movenial_users"], $movenial_users);

            // echoing JSON response
            echo json_encode($response);
        } 
        else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No contents found";

            // echo no users JSON
            echo json_encode($response);
        }    
} 
else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}

mysql_close($link_fetch_data);          
?>

そして、これはログです:

05-15 13:56:18.075: E/Buffer Error(7588): Error converting result java.lang.NullPointerException
05-15 13:56:18.075: E/JSON Parser(7588): Error parsing data org.json.JSONException: End of input at character 0 of 
05-15 13:56:18.085: E/AndroidRuntime(7588): FATAL EXCEPTION: main
05-15 13:56:18.085: E/AndroidRuntime(7588): java.lang.NullPointerException
05-15 13:56:18.085: E/AndroidRuntime(7588):     at com.example.movenialapplication.LogInActivity$1.onClick(LogInActivity.java:65)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at android.view.View.performClick(View.java:3538)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at  android.view.View$PerformClick.run(View.java:14330)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at android.os.Handler.handleCallback(Handler.java:608)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at android.os.Looper.loop(Looper.java:156)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at android.app.ActivityThread.main(ActivityThread.java:4987)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at java.lang.reflect.Method.invokeNative(Native Method)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at java.lang.reflect.Method.invoke(Method.java:511)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-15 13:56:18.085: E/AndroidRuntime(7588):     at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2

1

実際のデバイスが PC と同じネットワークに接続されているかどうかを確認します。PHP スクリプトが PC にある場合は、実際のデバイスの IP アドレスが PC と同じである必要があります。

これが役に立てば幸いです、幸運を祈ります^^

于 2013-05-28T00:21:48.830 に答える