2012-03-06 8 views
0

私はかなりの間この問題に取り組んできました。私は実際にデータベースから特定の場所にユーザーの評価を取得しようとしているし、それをアンドロイドに戻します。アンドロイドでは、データベースから情報を取得して、RatingBarで適切に評価を設定します。以下のコードの私のセグメントである:データベースからの評価とAndroidでのRatingBarの設定

ArrayList<NameValuePair> post_Parameters = new ArrayList<NameValuePair>(); 
    post_Parameters.add(new BasicNameValuePair("pID", placeID.toString())); 
    post_Parameters.add(new BasicNameValuePair("username", FootprintSession.getUsername().toString())); 

    String response2 = null; 

    try{ 

     response2 = (CustomHttpClient.executeHttpPost("http://test.com/getUserRating.php", post_Parameters)).toString(); 

     if(response.isEmpty()) 
     { 
       //trying to print out what is the response 
      Toast.makeText(getBaseContext(), "response"+response2, Toast.LENGTH_LONG).show(); 
      userRatingBar.setRating(defaultRating); 
     } 
     else 
     { 
      Toast.makeText(getBaseContext(), "Found : "+response2, Toast.LENGTH_LONG).show(); 
      userRating = (float)(Double.parseDouble(response2)); 
      userRatingBar.setRating(userRating); 
     } 

    }catch(Exception e){ 
     Log.e("Error in Rating",""+e); 
    } 

これは私のPHPの一部です:?

<?php 

$un = $_POST['username']; 
$pID = $_POST['pID']; 

$mysql_host = "localhost"; 
$mysql_database = "testDB"; 
$mysql_user = "testAdmin"; 
$mysql_password = "**********"; 

//connect to the database 
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_password); 

mysql_select_db($mysql_database, $conn); 

$query = "SELECT rating FROM fpRating WHERE username = '$un' AND placeID = '$pID' "; 
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error()); 

if(mysql_num_rows($result) == 0) { 
    echo null; 
}else 
{ 
    $row = mysql_fetch_assoc($result) 
    echo $row["rating"]; 
} 

>

**私のデータベースに 私の評価はdouble型です。

マイlogcatプリント: java.lang.NumberFormatException **

答えて

1

あなたが直接このように値をfloatに応答を変換することはできません。

このリンクはあなたに役立ちますandroid http response

関連する問題