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 trial
Nathan Pickard
10,950 Points@Override error
I am currently working through the "Implementing Designs for Android" track and I'm using android studio instead of eclipse. I've been adapting my code to make the project work in android studio, however I can't figure out how to fix the step I'm currently on now. I am getting an error on the following:
@Override public View onCreateView
@Override is underlined in red and the error message is saying "Method does not override method from its superclass". What do I do to correct this?
package apps.nathanpickard.ribbit.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import java.util.List;
import apps.nathanpickard.ribbit.adapters.UserAdapter;
import apps.nathanpickard.ribbit.utils.ParseConstants;
import apps.nathanpickard.ribbit.R;
/**
* Created by Nathan Pickard on 5/13/2015.
*/
public class EditFriendsFragment extends Activity {
public static final String TAG = EditFriendsFragment.class.getSimpleName();
protected List<ParseUser> mUsers;
protected ParseRelation<ParseUser> mFriendsRelation;
protected ParseUser mCurrentUser;
protected GridView mGridView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_friends, container, false);
mGridView = (GridView) findViewById(R.id.friendsGrid);
mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
return rootView;
}
@Override
public void onResume() {
super.onResume();
mCurrentUser = ParseUser.getCurrentUser();
mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.orderByAscending(ParseConstants.KEY_USERNAME);
query.setLimit(1000);
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> users, ParseException e) {
if (e == null) {
//Success
mUsers = users;
String[] usernames = new String[mUsers.size()];
int i = 0;
for (ParseUser user : mUsers) {
usernames[i] = user.getUsername();
i++;
}
if (mGridView.getAdapter() == null) {
UserAdapter adapter = new UserAdapter(EditFriendsFragment.this, mUsers);
mGridView.setAdapter(adapter);
} else {
((UserAdapter) mGridView.getAdapter()).refill(mUsers);
}
addFriendCheckmarks();
} else {
Log.e(TAG, e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(mGridView.getContext());
builder.setMessage(e.getMessage())
.setTitle(R.string.error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
// @Override
// public void onListItemClick(ListView l, View v, int position, long id) {
// super.onListItemClick(l, v, position, id);
//
// if(getListView().isItemChecked(position)) {
// // add the friend
// mFriendsRelation.add(mUsers.get(position));
// }
// else {
// // remove the friend
// mFriendsRelation.remove(mUsers.get(position));
// }
//
// mCurrentUser.saveInBackground(new SaveCallback() {
// @Override
// public void done(ParseException e) {
// if (e != null) {
// Log.e(TAG, e.getMessage());
// }
// }
// });
//
// }
private void addFriendCheckmarks() {
mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> friends, ParseException e) {
if (e == null) {
// list returned - look for a match
for (int i = 0; i < mUsers.size(); i++) {
ParseUser user = mUsers.get(i);
for (ParseUser friend : friends) {
if (friend.getObjectId().equals(user.getObjectId())) {
mGridView.setItemChecked(i, true);
}
}
}
} else {
Log.e(TAG, e.getMessage());
}
}
});
}
}