0

我正在做一个项目..当我在 2.2 版本 avd 中运行我的项目时,它以我的方式工作正常....但是当我在代码中使用 AsyncTask 并在 4.0 版本 avd 上运行时,它无法正常工作......我在我的 logcat 中发现了以下错误

  1. 解析数据时出错 java.net.SocketException:套接字已关闭
  2. 解析数据时出错 org.json.JSONException:对客户没有价值 我可以在我的代码中正确实现 AsyncTask 吗?请检查我的代码......出了什么问题......

             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();
            }
        }
    });
           }}
    
4

0 回答 0