I am working on a project.. when i have run my project in 2.2 version avd its work fine in my way.... but when i used AsyncTask in my code and run on 4.0 version avd its not work properly... i have found following errors in my logcat
- Error parsing data java.net.SocketException: Socket closed
Error parsing data org.json.JSONException: No value for customer can i implement properly the AsyncTask in my code? please check my code ... what's going to wrong is this....
public class Login extends Activity { String success, cus_id, cus_name; SessionManager session; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.login); Button submit = (Button) findViewById(R.id.loginbutton); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // TODO Auto-generated method stub com.amplio.MyCustomEditText et = (com.amplio.MyCustomEditText) findViewById(R.id.etmob); String mobileno = et.getText().toString(); if (mobileno.length() > 0) { final ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("cus_mob", mobileno)); Thread thread = new Thread() { @Override public void run() { try { String response = null; response = LoginHttpClient .executeHttpPost( "http://10.0.2.2/android/mobile_no.php", postParameters); System.out.println(response); JSONObject json = new JSONObject(response); JSONArray jArray = json .getJSONArray("customer"); for (int i = 0; i < jArray.length(); i++) { JSONObject json_data = jArray .getJSONObject(i); success = json_data.getString("success"); cus_id = json_data.getString("cus_id"); cus_name = json_data.getString("cus_name"); } if (success.equals("1")) { session = new SessionManager( getApplicationContext()); session.createLoginSessionRemMe(cus_id, cus_name); Intent iv = new Intent( getApplicationContext(), Verify.class); startActivity(iv); } else { // not valid email id or pass Toast.makeText(getApplicationContext(), "Incorrect Mobile No", Toast.LENGTH_LONG).show(); } } catch (Exception e) { } } }; thread.start(); } else { // display message if text fields are empty Toast.makeText(getBaseContext(), "Mobile no is required", Toast.LENGTH_SHORT).show(); } } }); }}