1
我想在我的數據庫中使用定時器插入值我開始使用定時器來顯示一個味精,它的工作,但是當我添加了th函數的調用插入值只是味精顯示和沒有數據插入!這裏是我的代碼android定時器處理程序java
public class TimertestActivity extends Activity {
private double lat;
private double lng;
Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
afficher();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
lat = 123456.98;
lng = 321654.78;
runnable.run();
}
public void afficher()
{
Toast.makeText(getBaseContext(),
"lat" +lat+ "lng" +lng,
Toast.LENGTH_SHORT).show();
insertvalues(lat, lng);
handler.postDelayed(runnable, 25000);
}
public void insertvalues(double lat, double lng){
//http post c à d envoi des données
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://www.pizza-paris.com/clic/marwa/test/form.php?lat="+lat+"&lng="+lng);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Log.i("postData", response.getStatusLine().toString());
}
catch(Exception e)
{
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
}
把你送到一個調試點HttpClient的HttpClient的=新DefaultHttpClient();通過調用來查看到底發生了什麼?你的清單中是否有互聯網許可要求? – Jack 2011-12-30 14:52:19
好thnx我忘了inetrnet許可!謝謝傑克!有些時候我們很難做到,忘記一些可以改變一切的細節! thnx :) – 2011-12-30 14:56:03