Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjenyufu
3,311 PointsCannot delete object: E/Delete Error๏น object not found for delete
So I am trying to delete a comment object in my own app that I am writing. And the object won't delete. In the log cat it says: "E/Delete Error: object not found for delete" How do I fix this? Here is my code:
public class PostThreadActivity extends ListActivity {
private SwipeRefreshLayout mSwipeRefreshLayout;
private ParseQueryAdapter<Comment> mainCommentAdapter;
private CommentAdapter favoriteCommentAdapter;
protected List<ParseObject> mComments; //create this member variable in order be able to delete comments
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_thread_layout);
getListView().setClickable(true);
Intent i = getIntent();
//Get the result of
String title = i.getStringExtra("title");
String location = i.getStringExtra("location");
String description = i.getStringExtra("description");
String rating = i.getStringExtra("ratings");
//String photo = i.getStringExtra("photo");
//TextViews of the singleItems
TextView titleTextView = (TextView) findViewById(R.id.title); //Get the textView for the title from item_list_favorites.xml and convert it to a variable titleTextView. Then gets the submitted Event title info from getters and setters: getTitle, then set it as text of TitleTextView //simple.
titleTextView.setText(title);
TextView locationTextView = (TextView) findViewById(R.id.location);
locationTextView.setText(location);
TextView descriptionTextView = (TextView) findViewById(R.id.description);
descriptionTextView.setText(description);
TextView ratingTextView = (TextView) findViewById(R.id.rating);
ratingTextView.setText(rating);
/*ParseImageView mealImage = (ParseImageView) findViewById(R.id.icon_in_post);
ParseFile photoFile = meal.getParseFile();
if (photoFile != null) {
mealImage.setParseFile(photoFile);
mealImage.loadInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// nothing to do
}
});
}
*/
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
mainCommentAdapter = new ParseQueryAdapter<Comment>(this, Comment.class);
mainCommentAdapter.setTextKey("commentText");
//mainCommentAdapter.setImageKey("photo");
favoriteCommentAdapter = new CommentAdapter(this);
// Default view is all comments
final ListView commentsListView = (ListView) findViewById(android.R.id.list);
commentsListView.setAdapter(mainCommentAdapter);
//adapt to show favorites adapter view
showFavoritesComments();
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Comment item = favoriteCommentAdapter.getItem(position);
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + position, Toast.LENGTH_LONG)
.show();
AlertDialog.Builder builder = new AlertDialog.Builder(PostThreadActivity.this);
builder.setTitle("DELETE COMMENT");
builder.setMessage("Are you sure you want to delete this comment?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Delete the comment
item.deleteInBackground(new DeleteCallback() {
@Override
public void done(ParseException e) {
Log.e("Delete Error", e.getMessage());
}
});
dialog.dismiss();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});