2016-11-08 4 views
0

私はアンドロイドの新機能です。私はログインページで作業していて、PHPとMySQLを使用してデータベースに接続しようとしていますが、 「アンドロイドサインインページ「残念なことに、アプリケーションは再配置されていません」エラー

Login.php

<?php 

if($_SERVER['REQUEST_METHOD']=='POST'){ 
    //Getting values 
    $username = $_POST['email']; 
    $password = $_POST['password']; 

    //Creating sql query 
    $sql = "SELECT * FROM users WHERE email='$username' AND password='$password'"; 

    //importing dbConnect.php script 
    require_once('dbConnect.php'); 

    //executing query 
    $result = mysqli_query($con,$sql); 

    //fetching result 
    $check = mysqli_fetch_array($result); 

    //if we got some result 
    if(isset($check)){ 
     //displaying success 
     echo "success"; 
    }else{ 
     //displaying failure 
     echo "failure"; 
    } 
    mysqli_close($con); 
} 

?>

Signin.java

import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.AppCompatButton; 
import android.view.View; 
import android.widget.Button ; 
import android.widget.EditText; 
    import android.widget.TextView; 
    import android.widget.Toast; 

    import com.android.volley.AuthFailureError; 
    import com.android.volley.Request; 
    import com.android.volley.RequestQueue; 
    import com.android.volley.Response; 
    import com.android.volley.VolleyError; 
    import com.android.volley.toolbox.StringRequest; 
    import com.android.volley.toolbox.Volley; 

    import java.util.HashMap; 
    import java.util.Map; 

    public class Signin extends AppCompatActivity implements View.OnClickListener { 

//Defining views 
private EditText editTextEmail; 
private EditText editTextPassword; 
public Button bsignin; 
final TextView textviewregister = (TextView) findViewById(R.id.textviewregister); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_signin); 



    editTextEmail = (EditText) findViewById(R.id.editTextEmail); 
    editTextPassword = (EditText) findViewById(R.id.editTextPassword); 
    bsignin = (Button) findViewById(R.id.bRegister); 
    //bsignin = (AppCompatButton) findViewById(R.id.bsignin); 



    bsignin.setOnClickListener(this); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    //In onresume fetching value from sharedpreference 
    SharedPreferences sharedPreferences = getSharedPreferences(SigninRequest.SHARED_PREF_NAME,Context.MODE_PRIVATE); 

    //Fetching the boolean value form sharedpreferences 
    boolean loggedIn = sharedPreferences.getBoolean(SigninRequest.LOGGEDIN_SHARED_PREF, false); 

    //If we will get true 
    if(loggedIn){ 
     //We will start the Profile Activity 
     Intent intent = new Intent(Signin.this, Profile.class); 
     startActivity(intent); 
    } 
} 

private void login(){ 
    //Getting values from edit texts 
    final String email = editTextEmail.getText().toString().trim(); 
    final String password = editTextPassword.getText().toString().trim(); 

    //Creating a string request 
    StringRequest stringRequest = new StringRequest(Request.Method.POST, SigninRequest.LOGIN_URL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        //If we are getting success from server 
        if(response.equalsIgnoreCase(SigninRequest.LOGIN_SUCCESS)){ 
         //Creating a shared preference 
         SharedPreferences sharedPreferences = Signin.this.getSharedPreferences(SigninRequest.SHARED_PREF_NAME, Context.MODE_PRIVATE); 

         //Creating editor to store values to shared preferences 
         SharedPreferences.Editor editor = sharedPreferences.edit(); 

         //Adding values to editor 
         editor.putBoolean(SigninRequest.LOGGEDIN_SHARED_PREF, true); 
         editor.putString(SigninRequest.EMAIL_SHARED_PREF, email); 

         //Saving values to editor 
         editor.apply(); 

         //Starting profile activity 
         Intent intent = new Intent(Signin.this, Profile.class); 
         startActivity(intent); 
        }else{ 
         //If the server response is not success 
         //Displaying an error message on toast 
         Toast.makeText(Signin.this, "Invalid username or password", Toast.LENGTH_LONG).show(); 
        } 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        //You can handle error here if you want 
       } 
      }){ 
     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      Map<String,String> params = new HashMap<>(); 
      //Adding parameters to request 
      params.put(SigninRequest.KEY_EMAIL, email); 
      params.put(SigninRequest.KEY_PASSWORD, password); 

      //returning parameter 
      return params; 
     } 
    }; 

    textviewregister.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v){ 
      Intent intent = new Intent(Signin.this,Signup.class); 
      startActivity(intent); 

     } 
    }); 

    //Adding the string request to the queue 
    RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(stringRequest); 
} 


@Override 
public void onClick(View v) { 
    //Calling the login function 
    login(); 
} 

}

SigninRequest.java

public class SigninRequest { 
public static final String LOGIN_URL = "http://localhost/Login.php/"; 


public static final String KEY_EMAIL = "email"; 
public static final String KEY_PASSWORD = "password"; 

//If server response is equal to this that means login is successful 
public static final String LOGIN_SUCCESS = "success"; 


public static final String SHARED_PREF_NAME = "Bonpost"; 

//This would be used to store the email of current logged in user 
public static final String EMAIL_SHARED_PREF = "email"; 

//We will use this to store the boolean in sharedpreference to track user is loggedin or not 
public static final String LOGGEDIN_SHARED_PREF = "loggedin"; 
enter code here 

}

+0

コーディングハッピー。 –

+0

Androidプログラムでデバッガを使ってみましたか? – Tim

+0

いいえ私はデバッガを使って試したことがありません –

答えて

0

1)の問題は、あなたのPHPスクリプトは、すべてのファイルのmysqliのやPDOの代わりに使用することを確認し、原因推奨されない設定にサーバ側の問題かもしれません非推奨の "msql"

2)すべてのアクティビティがマニフェストファイルに追加されていることを確認してください。

3)お使いの携帯電話またはテストデバイスがコンピュータと同じWi-Fiに接続されていることを確認します。

4)上記が役に立たない場合は、コードを書き直す手助けをします。

クラッシュがあった場合にスタックトレースを追加

+0

私はこれらの方法をすべて試しましたが、私はまだ同じ問題に直面しています –

関連する問題