gpt4 book ai didi

android - Parse.com 将 parseObject 添加到数据库异常 : Expected number, 但得到了一个数组

转载 作者:行者123 更新时间:2023-11-29 14:27:21 25 4
gpt4 key购买 nike

我有以下代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com