接続の新しいインスタンスを作成するアクティビティがあります。このような:
public class myActivity extends Activity {
TextView tv;
ProgressDialog dialog = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.daily_news);
gestureDetector = new GestureDetector(new SwipeGestureDetector());
tv = (TextView) findViewById(R.id.tx);
dialog = ProgressDialog.show(myActivity.this, "","Validating user...", true);
connection con = new connection(dialog);
final String str =con.connect_to_db("http://10.0.2.2:8000/daily/my.php");
runOnUiThread(new Runnable() {
public void run() {
tv.setText(str);
dialog.dismiss();
}
});
}
}
接続クラスには、null を返す HttpResponse があります。このような:
public class connection {
private HttpPost httppost;
private HttpClient httpclient;
private HttpResponse response;
private ProgressDialog dialog = null;
private String result;
public connection(ProgressDialog di){
dialog = di;
}
public String connect_to_db(String url){
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost(url);
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
result = httpclient.execute(httppost, responseHandler);
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
return result;
}
}
接続クラスの「結果」の値がnullなのはなぜですか?