我是Android編程的新手。我試圖用post發佈一些數據到服務器。我GOOGLE了它,並用此想出了:postData無法解析爲類型
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
我的問題是我得到這個代碼的第一行錯誤:
- POSTDATA不能被解析爲一個類型
- 語法令牌「{」,刪除標記「無效」,@此令牌
- 語法錯誤錯誤預期
我使用Eclipse和我使用d Shift + Ctrl + o獲取所有導入。
你的錯誤可能是高於此行...你缺少@Override或關閉大括號...等等... – forsvarir 2011-05-11 20:09:07
能告訴你的整個代碼? – 2011-05-11 20:09:14