android错误 - 从ms sql获取数据但不解析为活动
package com.example.am2610;

import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader; 
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.os.StrictMode;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

TextView text; 
ListView list; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    StrictMode.ThreadPolicy policy = new


StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    connect(); 
    System.out.println("connected");
}

private void connect() {
      String data;
      List<String> r = new ArrayList<String>();
      ArrayAdapter<String>adapter=new ArrayAdapter<String> 
      (getApplicationContext(), android.R.layout.simple_list_item_1,r);

      list=(ListView)findViewById(R.id.listView1);
        try {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet("http://192.168.25.4/d.php");
            HttpResponse response = client.execute(request);
            HttpEntity entity=response.getEntity();
            data=EntityUtils.toString(entity);
            Log.e("connect string", data);
            try {

       JSONArray json=new JSONArray(data);
       for(int i=0;i<json.length(); i++)
       {
        JSONObject obj=json.getJSONObject(i);
        String name=obj.getString("name");
        String year=obj.getString("year");
        String age=obj.getString("age");
        Log.e("error in connect", name);
        r.add(name);
        r.add(year);
        r.add(age);  

        list.setAdapter(adapter);

       }

      } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

        } catch (ClientProtocolException e) {
            Log.d("HTTPCLIENT", e.getLocalizedMessage());
        } catch (IOException e) {
            Log.d("HTTPCLIENT", e.getLocalizedMessage());
        }

    }

}

................................................................................ log cat error:-

10-31 11:27:08.174: E/connect string(3365): {"mail_master":
[{"mail_id":2,"mail_code":"yy_yyy@yahoo.com","mail_name":"Mr yyyy"},
{"mail_id":3,"mail_code":"xxx@xxx.lk","mail_name":"Mr xxxx"},
dtz46697
dtz46697 更清楚问题并仅发布代码的相关部分
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐