void update(){
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://164.125.69.164:80/update.php"); // make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(3);
// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
nameValuePairs.add(new BasicNameValuePair("userID",ID.toString().trim()));
nameValuePairs.add(new BasicNameValuePair("userHeight",heightUpdate.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("userWeight",weightUpdate.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
if(response.equalsIgnoreCase("Complete")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(Update.this,"Update Success", Toast.LENGTH_SHORT).show();
dialog.dismiss();
finish();
}
});
}
else{
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(Update.this,"Update Fail", Toast.LENGTH_SHORT).show();
dialog.dismiss();
finish();
}
});
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
}
위 코드로 Insert, Compare 등 여러가지 작업을 했는데 update를 할려니 계속 Exception : null 이 발생하네요...
httppost는 값이 들어가는것 같은데 그 이후 작업이 아무것도 진행이 안됩니다... 왜이런거죠... ㅠ
아 참고로 이 액티비티가 호출되기 전 액티비티에서 AsyncTask를 이용해서 DB 값을 불러와 값들을 세팅하는 작업을 하였습니다. 예를들어 AsyncTask를 이용해서 프로필을 불러와서 수정사항이 있어 UPDATE를 하기 위해 UPDATE 버튼을 눌러서 위와같은 코드를 가진 액티비티가 호출되는것입니다.