获取HTML表单的响应

时间:2014-12-24 06:53:48

标签: android

我的节目是

package com.vss.lcm.gps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.googlemap.MainActivity2;
import com.example.googlemap.R;

public class Supervisornew1 extends Activity {

    Button bt;
    EditText et;
    private ProgressDialog pDialog;
    String id;

    // private static String url =
    // "http://dyandroidapps.netii.net/dygettinglatlng.php";
    private static String url = "http://www.vsstechnologyapp.in/deliverytrack_db/dygettinglatlng.php";
    // JSON parser class
    // JSONPARSER1 jsonParser = new JSONPARSER1();

    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_CONTACTS = "product";
    private static final String TAG_LAT = "lat";
    private static final String TAG_LNG = "lng";

    // contacts JSONArray
    // JSONArray contacts = null;
    JSONArray contacts = null;
    // Hashmap for ListView
    ArrayList<HashMap<String, String>> contactList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.supervisor);

        et = (EditText) findViewById(R.id.edittext_gettingmobnumber);
        bt = (Button) findViewById(R.id.btn_supervisor);

        contactList = new ArrayList<HashMap<String, String>>();

    }

    public void track(View v) {
        // new LoadAllProducts().execute();
        id = et.getText().toString();
        if (id.trim().matches("") || id.trim().length() < 10
                || id.trim().length() > 10) {
            Toast.makeText(getApplicationContext(),
                    "Please Enter Valid 10 Digit Number", Toast.LENGTH_SHORT)
                    .show();
        } else {

            new GetContacts().execute();
            // Toast.makeText(getApplicationContext(), id,
            // Toast.LENGTH_SHORT).show();
            // new RetrieveTask().execute();
        }
    }

    // private class GetContacts extends AsyncTask<Void, ArrayList<String>,
    // Void>
    // class GetContacts extends AsyncTask<String, String, String> {
    private class GetContacts extends AsyncTask<Void, ArrayList<String>, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(Supervisornew1.this);
            pDialog.setMessage("Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        protected Void doInBackground(Void... arg0) {
            /*
             * // protected String doInBackground(String... params) {
             * 
             * // ServiceHandler sh = new ServiceHandler();
             * 
             * // updating UI from Background Thread runOnUiThread(new
             * Runnable() { public void run() { // Check for success tag int
             * success;
             */
            // try {
            ServiceHandler sh = new ServiceHandler();
            // Building Parameters

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            id = et.getText().toString();
            params.add(new BasicNameValuePair("id",id));
            // params.add(new BasicNameValuePair("name", "deepak"));

            String jsonStr = sh.makeServiceCall(url, ServiceHandler.POST,
                    params);
            System.out.print(jsonStr);
            Log.d("Response Is This", "> " + jsonStr);
            String str = jsonStr;
            try {
                if (jsonStr != null) {
                    JSONObject joj = new JSONObject(str);
                    JSONArray contacts = joj.getJSONArray(TAG_CONTACTS);
                    for (int i = 0; i < contacts.length(); i++) {
                        JSONObject c = contacts.getJSONObject(i);

                        String lat = c.getString(TAG_LAT);
                        String lng = c.getString(TAG_LNG);

                        Log.d("response", lat);
                        Log.d("response", lng);

                        HashMap<String, String> map = new HashMap<String, String>();
                        map.put("lat", lat);
                        map.put("lng", lng);
                        contactList.add(map);
                    }

                    if (contactList != null) {
                        Intent intentmap = new Intent(Supervisornew1.this,
                                MainActivity2.class);
                        intentmap.putExtra("arraylist", contactList);
                        startActivityForResult(intentmap, 500);
                    } else {
                        // product with pid not found
                        Toast.makeText(getApplicationContext(),
                                "No Record Found.Please Check Mobile Number",
                                Toast.LENGTH_SHORT).show();
                    }

                } else {
                    Toast.makeText(getApplicationContext(),
                            "No Record Found.Please Check Mobile Number",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(Void result) {
            // dismiss the dialog once got all details
            // pDialog.cancel();
            if (pDialog != null && pDialog.isShowing()) {
                pDialog.cancel();
            }

        }
    }
}

我的错误日志是

    12-24 01:44:45.149: D/Response Is This(1531):    - Unfortunately, Microsoft has added a clever new

12-24 01:44:45.149: D/Response Is This(1531):    - "feature" to Internet Explorer. If the text of

12-24 01:44:45.149: D/Response Is This(1531):    - an error's message is "too small", specifically

12-24 01:44:45.149: D/Response Is This(1531):    - less than 512 bytes, Internet Explorer returns

12-24 01:44:45.149: D/Response Is This(1531):    - its own error message. You can turn that off,

12-24 01:44:45.149: D/Response Is This(1531):    - but it's pretty tricky to find switch called

12-24 01:44:45.149: D/Response Is This(1531):    - "smart error messages". That means, of course,

12-24 01:44:45.149: D/Response Is This(1531):    - that short error messages are censored by default.

12-24 01:44:45.149: D/Response Is This(1531):    - IIS always returns error messages that are long

12-24 01:44:45.149: D/Response Is This(1531):    - enough to make Internet Explorer happy. The

12-24 01:44:45.149: D/Response Is This(1531):    - workaround is pretty simple: pad the error

12-24 01:44:45.149: D/Response Is This(1531):    - message with a big comment like this to push it

12-24 01:44:45.149: D/Response Is This(1531):    - over the five hundred and twelve bytes minimum.

12-24 01:44:45.149: D/Response Is This(1531):    - Of course, that's exactly what you're reading

12-24 01:44:45.149: D/Response Is This(1531):    - right now.

12-24 01:44:45.149: D/Response Is This(1531):    -->

12-24 01:44:45.189: W/System.err(1531): org.json.JSONException: Value <HTML> of type java.lang.String cannot be converted to JSONObject
12-24 01:44:45.249: W/System.err(1531):     at org.json.JSON.typeMismatch(JSON.java:111)
12-24 01:44:45.249: W/System.err(1531):     at org.json.JSONObject.<init>(JSONObject.java:159)
12-24 01:44:45.249: W/System.err(1531):     at org.json.JSONObject.<init>(JSONObject.java:172)
12-24 01:44:45.249: W/System.err(1531):     at com.vss.lcm.gps.Supervisornew1$GetContacts.doInBackground(Supervisornew1.java:123)
12-24 01:44:45.249: W/System.err(1531):     at com.vss.lcm.gps.Supervisornew1$GetContacts.doInBackground(Supervisornew1.java:1)
12-24 01:44:45.249: W/System.err(1531):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-24 01:44:45.259: W/System.err(1531):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-24 01:44:45.259: W/System.err(1531):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-24 01:44:45.259: W/System.err(1531):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-24 01:44:45.259: W/System.err(1531):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-24 01:44:45.259: W/System.err(1531):     at java.lang.Thread.run(Thread.java:841)

这个程序在我改变这个应用程序的服务器之前工作正常,但是当我改变服务器时突然得到这个神。 我无法理解这个问题,如果有任何解决方案请建议我。 感谢

0 个答案:

没有答案