大家好抱歉打扰你,但Azure给了我很多麻烦。我试图在数据库中插入评论我使用以下代码来定义评论:
package com.example.discovermalta;
/**
* Created by Josmar Grech on 23/12/2015.
*/
public class Review {
@com.google.gson.annotations.SerializedName("id")
private String mId;
@com.google.gson.annotations.SerializedName("content")
private String mContent;
@com.google.gson.annotations.SerializedName("userId")
private String mUserId;
@com.google.gson.annotations.SerializedName("poiId")
private String mPoiId;
@com.google.gson.annotations.SerializedName("place")
private String mPlace;
@com.google.gson.annotations.SerializedName("rating")
private String mRating;
public Review()
{
}
public Review( String mContent, String mUserId, String mPoiId, String mPlace, String mRating)
{
this.mContent = mContent;
this.mUserId = mUserId;
this.mPoiId = mPoiId;
this.mPlace = mPlace;
this.mRating = mRating;
}
public String getId(){return mId;}
public void setId(String mId){this.mId = mId;}
public String getContent(){return mContent;}
public void setContent(String mContent){this.mContent = mContent;}
public String getUserId(){return mUserId;}
public void setUserId(String mUserId){this.mUserId = mUserId;}
public String getPoiId(){return mPoiId;}
public void setPoiId(String mPoiId){this.mPoiId = mPoiId;}
public String getPlace(){return mPlace;}
public void setPlace(String mPlace){this.mPlace = mPlace;}
public String getRating(){return mRating;}
public void setRating(String mRating){this.mRating = mRating;}
@Override
public boolean equals(Object o) {
return o instanceof Review && ((Review) o).mId == mId;
}
}
azure中的评论表由以下内容组成: id - 整数 - 索引 content - varchar userId - int poiId - int 地方 - varchar rating - int
要将评论添加到数据库中,我使用以下代码:
public void add_reviewclick(View v){
placeEditText =(EditText) findViewById(R.id.placeEditText);
contentEditText =(EditText) findViewById(R.id.contentEditText);
ratingBar = (RatingBar) findViewById(R.id.addRatingBar);
place = placeEditText.getText().toString();
content = contentEditText.getText().toString();
rating = Float.toString(ratingBar.getRating());
AddReviewToTable(place, rating, content);
}
public void AddReviewToTable(String place, String rating, String content) {
Review review = new Review();
review.setPlace(place);
review.setContent(content);
review.setRating(rating);
review.setUserId("1");
review.setPoiId("1");
final Review newrev = review;
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
addReviewtoMobileService(newrev);
} catch (final Exception e) {
Log.e("TEST", e.toString());
}
return null;
}
};
runAsyncTask(task);
}
private void addReviewtoMobileService(Review review) {
try{
Review newrev = review;
Log.i("Place", newrev.getPlace());
// reviewTable.insert(newrev);
reviewTable.insert(newrev);
Log.i("RevDialog", "inserted suppost");
}catch (Exception e){
};
}
如果有人可以提供帮助,我过去3周一直在努力,我会非常感激 提前致谢