jeudi 13 août 2015

E/AndroidRuntime(274): java.lang.RuntimeException: An error occured while executing doInBackground()

pliiiiiiiiiiiiiiiiz help me i am trying to program an application android but i have an error in my aplication whene i click the button

here is the error:

08-13 22:50:56.182: E/AndroidRuntime(276): FATAL EXCEPTION: AsyncTask #1
08-13 22:50:56.182: E/AndroidRuntime(276): java.lang.RuntimeException: An error occured while executing doInBackground()
08-13 22:50:56.182: E/AndroidRuntime(276):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.lang.Thread.run(Thread.java:1096)
08-13 22:50:56.182: E/AndroidRuntime(276): Caused by: java.lang.NullPointerException
08-13 22:50:56.182: E/AndroidRuntime(276):  at com.example.massarv4.Login$AttemptLogin.doInBackground(Login.java:78)
08-13 22:50:56.182: E/AndroidRuntime(276):  at com.example.massarv4.Login$AttemptLogin.doInBackground(Login.java:1)
08-13 22:50:56.182: E/AndroidRuntime(276):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-13 22:50:56.182: E/AndroidRuntime(276):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

login.java

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 com.example.massarv4.JSONParser;
import com.example.massarv4.OtherActivity;

import android.app.Activity; 
import android.app.ProgressDialog; 
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle; 
import android.util.Log;
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText;
import android.widget.Toast; 
public class Login extends Activity implements OnClickListener{ 
    private EditText user, pass; 
    private Button bLogin;
    // Progress Dialog 
    private ProgressDialog pDialog; 
    // JSON parser class 
    JSONParser jsonParser = new JSONParser(); 
    private static final String LOGIN_URL = "http://ift.tt/1TxPFcU"; 
    private static final String TAG_SUCCESS = "success"; 
    private static final String TAG_MESSAGE = "message";
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.login);
        user = (EditText)findViewById(R.id.username); 
        pass = (EditText)findViewById(R.id.password); 
        bLogin = (Button)findViewById(R.id.login);
        bLogin.setOnClickListener(this);
        } 
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub 
        switch (v.getId()) { 
        case R.id.login: new AttemptLogin().execute(); 
        // here we have used, switch case, because on login activity you may
        //also want to show registration button, so if the user is new ! we can go the 
        //registration activity , other than this we could also do this without switch //case. 
        default: break; 
        }
        } 
    class AttemptLogin extends AsyncTask<String, String, String> {
        /** * Before starting background thread Show Progress Dialog * */ 
        boolean failure = false;
        @Override
        protected void onPreExecute() { 
            super.onPreExecute();
            pDialog = new ProgressDialog(Login.this);
            pDialog.setMessage("Attempting for login...");
            pDialog.setIndeterminate(false); 
            pDialog.setCancelable(true); pDialog.show(); 
            } 
        @Override
        protected String doInBackground(String... args) { 
            // TODO Auto-generated method stub // here Check for success tag 
            int success=0; 
            String username = user.getText().toString();
            String password = pass.getText().toString();
            try {
                List<NameValuePair> params = new ArrayList<NameValuePair>(); 
                params.add(new BasicNameValuePair("username", username));
                params.add(new BasicNameValuePair("password", password)); 
                Log.d("request!", "starting"); 
                JSONObject json = jsonParser.makeHttpRequest( LOGIN_URL, "POST", params); 
                // checking log for json response 
                Log.d("Login attempt", json.toString());
                // success tag for json 
                success = json.getInt(TAG_SUCCESS); 
                if (success == 1) { Log.d("Successfully Login!", json.toString());
                Intent ii = new Intent(Login.this,OtherActivity.class); finish(); 
                // this finish() method is used to tell android os that we are done with current 
                //activity now! Moving to other activity 
                startActivity(ii);
                return json.getString(TAG_MESSAGE);
                }else{ 
                    return json.getString(TAG_MESSAGE); 
                    } }
            catch (JSONException e) { 
                e.printStackTrace(); 
                } 
            return null; 
            }
        /** * Once the background process is done we need to Dismiss the progress dialog asap * **/ 
        protected void onPostExecute(String message) { pDialog.dismiss()
            ; if (message != null){
                Toast.makeText(Login.this, message, Toast.LENGTH_LONG).show(); 
                }
            }
        }



        }

login.php

<?php mysql_connect("localhost","root",""); 
$db= mysql_select_db("massar"); 
$pas=$_POST["password"];
$usr=$_POST["username"];
if (!empty($_POST)) { 
    if (empty($_POST['username']) || empty($_POST['password'])) { 
    // Create some data that will be the JSON response 
    $response["success"] = 0; $response["message"] = "One or both of the fields are empty ."; 
    //die is used to kill the page, will not let the code below to be executed. It will also //display the parameter, that is the json data which our android application will parse to be 
    //shown to the users 
    die(json_encode($response)); 
    } 
    $query = " SELECT * FROM parent WHERE CIN = $usr and MotDePasse = $pas "; 
    $sql1=mysql_query($query); 
    $row = mysql_fetch_array($sql1); 
        if (!empty($row)) { 
    $response["success"] = 1; 
    $response["message"] = "You have been sucessfully login";
    die(json_encode($response));
    } else{ 
        $response["success"] = 0; 
        $response["message"] = "invalid username or password "; 
        die(json_encode($response)); } } else{ $response["success"] = 0; 
        $response["message"] = " One or both of the fields are empty "; 
        die(json_encode($response));
        } mysql_close(); 
        ?>

i need your help pliiz I got stuck



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire