private String s;
EditText numDisplay;
Button calculateNow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numDisplay= (EditText)findViewById(R.id.editText1);
calculateNow = (Button)findViewById(R.id.button1);
s=numDisplay.toString();
calculateNow.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
// Perform action on click
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://primecalculation.appspot.com/");
try {
// Add your data
@SuppressWarnings("deprecation")
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("value", s));
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
} }
} );}}
我写了上面的代码来发布一个从用户那里得到的号码,并希望输入的号码在服务器上发布。
但是我按下按钮&#34后运行程序我发现错误;不幸的是停止了工作&#34;。
任何帮助表示感谢。