Parse.com将parseObject添加到数据库异常:预期的数字,但得到了一个数组

use*_*244 1 arrays android 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();
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)

当我调试代码时,当它到达"public void done(ParseException e)"时,异常(e)打印:

com.parse.ParseException:密钥BusNumber的无效类型,预期数量,但得到数组.

我有点被蒙住眼睛,我不明白为什么我收到这个错误,因为我正在将文本从EditText转换为int,并且它仍然说它是一个数组.

感谢您的时间!

use*_*244 9

解决了它.问题是我使用的是parseObject.add(用于数组).要为数据库放置单个值,您需要使用parseObject.put(用于单个项目).否则你会得到我的例外.我在这里写这个,也许有人会看到同样的问题.

干杯!