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

标签 android arrays parse-platform android-studio

我有以下代码:

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/

相关文章:

java - 返回 float 组方法

Java Array 2D 无法使用参数

javascript - 仅使用 JavaScript 中的 Parse 验证密码

android - 阴影贴图在 Android 上的 OpenGL ES 3.0 中不起作用

android - 应用程序启动、停止和暂停时的事件

c++ - 将数组分配给多维数组,反之亦然

python - 从 Parse Cloud Code 运行 python 脚本(后台作业)

node.js - 如何将自定义 ObjectId 添加到解析服务器对象?

android - 邮件设置配置文件(mobileconfig替代)

java - 无法在 android 模拟器中安装 apk。应用程序包含 ARM 原生代码