0

下面是我的代码,

package com.ord.bus;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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 android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void postData() {
        // Creates a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://egged.co.il/eggedGoogle/Default.aspx");

        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
            nameValuePairs.add(new BasicNameValuePair("state", "3"));
            nameValuePairs.add(new BasicNameValuePair("company","1"));
            nameValuePairs.add(new BasicNameValuePair("language","he"));
            nameValuePairs.add(new BasicNameValuePair("freelang","480"));
            nameValuePairs.add(new BasicNameValuePair("width","400"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            BufferedReader rd = new BufferedReader((Reader) response);
            String res = null;
            String line = null;
            while ((line = rd.readLine()) != null) {
                res += line;
            }
            TextView txt = (TextView) findViewById(R.id.textView1);
            txt.setText(res);

        } catch (ClientProtocolException e) {}  
         catch (IOException e) {}       
    }
}
  1. 为什么我不能在 Eclipse 中逐行调试?每次我按 f5 时都会出现“找不到源”错误。
  2. 我试图将数据从 android 设备发送到帖子,并从网站获取巴士时间。不知何故,我找不到我的代码的问题,但你的程序不断崩溃,有没有机会寻求帮助?
4

0 回答 0