0

ユーザーの場所を取得するアプリを接続しようとしていました.今、mysqlデータベースを使用してphpサーバーでアプリを更新したかったのです。コードの一部でエラーが発生しています

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceid = telephonyManager.getDeviceId();



    //this is JSON part to put your information inside it
    String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"deviceid\":\""+deviceid+"\"}}";


    HttpClient httpClient = new DefaultHttpClient();

    // Post method to send data to server
    HttpPost post = new HttpPost("http://location.site.net/storeg.php");

}
        InputStream is; 

        String result = ""; 
        //the year data to send 
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
        nameValuePairs.add(new BasicNameValuePair("deviceid", +deviceid));
        nameValuePairs.add(new BasicNameValuePair("latitude", +latitude));
        nameValuePairs.add(new BasicNameValuePair("longitude", +longitude));
        { 

        //http post 
        try{ 
                HttpClient httpclient = new DefaultHttpClient(); 
                HttpPost httppost = new HttpPost("http://location.site.net/storeg.php"); 
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
                HttpResponse response = httpclient.execute(httppost);  
                HttpEntity entity = response.getEntity(); 
                is = entity.getContent(); 
                Log.e("log_tag", "connection success "); 
                Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
        }catch(Exception e){ 
                Log.e("log_tag", "Error in http connection "+e.toString()); 
                Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show(); 

        } 
        //convert response to string 
        try{ 
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
                StringBuilder sb = new StringBuilder(); 
                String line = null; 
                while ((line = reader.readLine()) != null) { 
                        sb.append(line + "\n"); 
                        Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
                } 
                is.close(); 

                result=sb.toString(); 
        }catch(Exception e){ 
               Log.e("log_tag", "Error converting result "+e.toString()); 
            Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show(); 

        } 

        //parse json data 
        try{ 
                JSONArray jArray = new JSONArray(result); 
                for(int i=0;i<jArray.length();i++){ 
                       JSONObject json_data = jArray.getJSONObject(i); 
                        Log.i("log_tag","deviceid: "+json_data.getInt("deviceid")+ 
                                ", latitude: "+json_data.getString("latitude")+ 
                                ", longitude: "+json_data.getInt("longitude")); 
                        Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
               } 

        }catch(JSONException e){ 
                Log.e("log_tag", "Error parsing data "+e.toString()); 
                Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show(); 
        } 
    } 
} 

.add部分でエラーが発生しました。これを手伝ってください。コードは緯度と経度を投稿します。

4

1 に答える 1

0

これらの行から「+」記号を削除します

    nameValuePairs.add(new BasicNameValuePair("deviceid", +deviceid));
    nameValuePairs.add(new BasicNameValuePair("latitude", +latitude));
    nameValuePairs.add(new BasicNameValuePair("longitude", +longitude));

それらを作るために

    nameValuePairs.add(new BasicNameValuePair("deviceid", deviceid));
    nameValuePairs.add(new BasicNameValuePair("latitude", latitude));
    nameValuePairs.add(new BasicNameValuePair("longitude", longitude));

私はこれがうまくいくと思う

于 2012-05-16T05:03:38.323 に答える