Android Studio Debug无法启动

时间:2013-08-26 17:25:38

标签: android http android-studio

当我的应用程序到达该行时崩溃:

HttpEntity entity  = response.getEntity();

我不知道为什么,所以我试图在调试模式下运行,但Android Studio一直告诉我:

  

警告:调试信息可能不可用。请关闭其他申请   使用ADB:Monitor,DDMS,Eclipse

我没有打开任何其他东西,事实上我只是重置了PC。

以下是我的全部代码:

package com.clientserver.jsontest;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

/**
 * Created by Gabriel on 25/08/13.
 */
public class SyncActivity extends Activity {

    private TextView display;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sync_activity);

        initComponents();

        String name = "Gabriel";

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("nameToSearch", name));

        HttpParams httpParameters = new BasicHttpParams();

        HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
        HttpConnectionParams.setSoTimeout(httpParameters, 15000);

        HttpClient httpClient = new DefaultHttpClient(httpParameters);

        HttpPost httpPost = new HttpPost("http://10.0.0.6/jsonTest/login.php");
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }


        HttpResponse response = null;

        try {
            response = httpClient.execute(httpPost);
        } catch (IOException e) {
            e.printStackTrace();
        }

        HttpEntity entity  = response.getEntity(); //ERROR ON THIS LINE



        String result = "Nothing";



        try {
            result = EntityUtils.toString(entity);
        } catch (IOException e) {
            e.printStackTrace();
        }



        JSONObject jsonObject = null;

        try {
            jsonObject = new JSONObject(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        int numint = 0;
        String clientName = "";
        String email = "";
        double amount = 0;

        try {
            numint = jsonObject.getInt("numint");
            clientName = jsonObject.getString("name");
            email = jsonObject.getString("email");
            amount = jsonObject.getDouble("amount");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String text = numint + " "+ clientName + " " + email + " " + amount;

        display.setText(text);

    }

    public void initComponents() {
        display = (TextView) findViewById(R.id.textView);
    }
}

0 个答案:

没有答案
相关问题