我有以下代码:
buttonAddAlert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(AddAlert.this.isOnline()){
if(busNumber.getText().toString().isEmpty() || description.getText().toString().isEmpty()){
Toast.makeText((Context)(AddAlert.this.getBaseContext()), (CharSequence)("Please fill all the fields!"), (int)(Toast.LENGTH_SHORT)).show();
}
else {
ParseObject parseObject = new ParseObject("AlertsClass");
parseObject.add("BusNumber", Integer.parseInt(busNumber.getText().toString()));
parseObject.add("Description", description.getText().toString());
//requestLocation();
parseObject.add("Coordinates", new ParseGeoPoint(currentLatitude, currentLongitude));
parseObject.saveEventually(new SaveCallback() {
@Override
public void done(ParseException e) {
Intent recentSightingsPageIntent = new Intent(AddAlert.this, RecentSightings.class);
startActivity(recentSightingsPageIntent);
}
});
}
}
else{
Toast.makeText((Context)(AddAlert.this.getBaseContext()), (CharSequence)("Your internet connection is offline"), (int)(Toast.LENGTH_SHORT)).show();
}
}
});
当我调试代码时,当它到达“public void done(ParseException e)”时,exception(e) 打印:
com.parse.ParseException: invalid type for key BusNumber, expected number, but got array.
我有点蒙住眼睛,我不明白为什么会收到此错误,因为我正在将文本从 EditText 转换为 int,但它仍然说它是一个数组。
感谢您的宝贵时间!
最佳答案
解决了。问题是我正在使用 parseObject.add(用于数组)。要将单个值放入数据库,您需要使用 parseObject.put(用于单个项目)。否则你会得到我的异常(exception)。我写在这里,也许有人会遇到同样的问题。
干杯!
关于android - Parse.com 将 parseObject 添加到数据库异常 : Expected number, 但得到了一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26364327/