Reputation: 177
I have the following code:
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();
}
}
});
As I am debugging the code, when it reaches the "public void done(ParseException e)" the exception(e) prints:
com.parse.ParseException: invalid type for key BusNumber, expected number, but got array.
I am a bit blindfolded, and i cannot see why I am receiving this error, because i am converting the text from the EditText to int, and still it says it is an array.
Thank you for your time!
Upvotes: 1
Views: 1150
Reputation: 360
You should not use addObject:forKey:
. The parse Object is actually dictionary so try using setObject:forKey:
Upvotes: 0
Reputation: 177
Solved it. The problem was that i was using parseObject.add(which is used for arrays). To put a single value the database, you need to use parseObject.put(which is used for a single item). Otherwise you will get my exception. I am writing this here, maybe someone will see it with the same problem.
Cheers!
Upvotes: 9