1

I had this piece of code I borrowed from the internet work well on android 2.3.3 API 10; however it gave me errors on 4.0 API 14. I'm not good at coding I need precise correction on how it can work not reference to other documentations.

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
         // Check for success tag
        int success;
        String username = user.getText().toString();
        String password = pass.getText().toString();
        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("user_name", username));
            params.add(new BasicNameValuePair("password", password));

            Log.d("request!", "starting");
            // getting product details by making HTTP request
            JSONObject json = jsonParser.makeHttpRequest(
                   LOGIN_URL, "POST", params);

            // check your log for json response
            Log.d("Login attempt", json.toString());

            // json success tag
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Login Successful!", json.toString());

                Intent i_login = new Intent(Login.this, Concurency_main.class);
                i_login.putExtra ( "TextBox_user", user.getText().toString() );


                finish();
                startActivity(i_login);
                return json.getString(TAG_MESSAGE);
            }else{
                Log.d("Login Failure. Invalid username/password ", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
  • What are the errors? – F43nd1r Apr 06 '16 at 08:06
  • Multiple markers at this line - NameValuePair cannot be resolved to a type – Gilbert Hair Apr 06 '16 at 08:17
  • List params = new ArrayList(); params.add(new BasicNameValuePair("user_name", username)); params.add(new BasicNameValuePair("password", password)); the errors are on these lines of code – Gilbert Hair Apr 06 '16 at 08:18
  • 5 second google search and I found this http://stackoverflow.com/questions/29378012/namevaluepair-deprecated-for-openconnection you clearly didn't research your problem. – F43nd1r Apr 06 '16 at 08:19

0 Answers0