无法将变量发送到php端(两个问题)

时间:2013-12-01 15:11:46

标签: java android eclipse variables

我正在尝试将变量移动到服务器端,但我无法让它工作。 我在其中一个线程中有一个示例代码,它(几乎)可以工作。

我目前的代码:

public void mahGPSbutton() {


    Button myGPS_button = (Button) findViewById(R.id.GPS_button);
    myGPS_button.setTextColor(Color.CYAN);
    myGPS_button.setOnClickListener(new View.OnClickListener() {
                                                                                                                              //#
        public void onClick(View v) {   
            LocationManager locationManager = (LocationManager) MainActivity.this.getSystemService(Context.LOCATION_SERVICE); //#
            LocationListener locationListener = new LocationListener() {                                                      //#
                public void onLocationChanged(Location location) {
                    double MyLat = location.getLatitude();
                    double MyLong = location.getLongitude();
                    double MyAlt = location.getAltitude();
                    String MyProvider = location.getProvider();
                    float MyAccuracy = location.getAccuracy();
                }
                    public void sender() {
                    String url = "www.IP/FOLDER/Binder.php?myLat="+ MyLat;
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    HttpGet request = new HttpGet();
                    request.setURI(null);
                    try {
                        HttpResponse httpResponse = httpClient.execute(request);
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                public void onStatusChanged(String provider, int status, Bundle extras) {}                                    //#
                public void onProviderEnabled(String provider) {}                                                             //#
                public void onProviderDisabled(String provider) {}
                //#
            };                                                                                                                //#
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
                                                                                                              //#
        }                                                                                                                     //#
    }); 
}                       

问题在线&线;

String url = "www.IP/FOLDER/Binder.php?myLat="+ MyLat;
request.setURI(null);

MyLat给了我一个错误:“MyLat无法解析为变量”,我理解为什么它给了我这个,但我不知道解决它的方法。 然后 request.setURI(NULL); 这没关系,但是当我将null更改为URI时,它会给我以下错误: “HttpRequestBase类型中的方法setURI(URI)不适用于参数” 我得不到它,并且不知道修复它的方法......

任何帮助都没关系

1 个答案:

答案 0 :(得分:0)

而不是将Null传递给HttpGet.setURI(null);你应该将URI传递为:

String url = "www.IP/FOLDER/Binder.php?myLat="+ MyLat;
URI url_uri = new URI(url); 
request.setURI(url_uri);

或使用HttpGet(String uri)创建实例:

HttpGet request = new HttpGet(url);