Issue working with parse - object cannot be resolved - java

I am trying to populate a page with information about user such name, age and profile picture from parse. In attempting so, I have encountered some issues such as:
Along with formatting errors such as
, I am encountering the following issue:
1) object cannot be resolved
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> users,ParseException e) {
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
});
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
Update
I have added another picture

You didn't post enough code to show where the missing or extra bracket is. Just go through your code carefully, work your way outward, collapsing methods etc as you go.

I think you should have something like below to iterate over the list:
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseObject> objects,ParseException e) {
for(int i=0;i<objects.size();i++){
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = objects.get(i).getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
}//for loop
});

Related

Checking Checkboxes In Custom Listview From Parse.com

i'm facing a problem of logic.
I'm getting data from Parse.com and i need to mark checkboxes as checked if the current user is liking a card.
Everything works fine but i have to scroll down and up to change the status of the checkboxes
here is my code
public class CardsFragment extends ListFragment {
public static final String TAG = CardsFragment.class.getSimpleName();
protected List<ParseObject> mCards;
protected ParseRelation<ParseObject> mUserCategoriesRelation;
protected ParseRelation<ParseObject> mCardsLikeRelation;
protected ParseUser mCurrentUser;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_cards, container,
false);
return rootView;
}
#Override
public void onResume() {
super.onResume();
getActivity().setProgressBarIndeterminateVisibility(true);
final List<CardModel> list = new ArrayList<CardModel>();
mCurrentUser = ParseUser.getCurrentUser();
mCardsLikeRelation = mCurrentUser.getRelation("cardLikesRelation");
mUserCategoriesRelation = mCurrentUser.getRelation(ParseConstants.KEY_CATEGORIES_RELATION);
ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseConstants.CLASS_CARD);
query.whereEqualTo(ParseConstants.KEY_DELETED, false);
query.orderByDescending(ParseConstants.KEY_CREATED_AT);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> cards, ParseException e) {
getActivity().setProgressBarIndeterminateVisibility(false);
if (e == null) {
mCards = cards;
for (final ParseObject card : mCards) {
list.add(get(card.getString("title"), card.getString("content"), card.getString("background"), card.getBoolean("background_image"),card.getInt("likes")));
}
if (getListView().getAdapter() == null) {
ArrayAdapter<CardModel> adapter = new CardAdapter(getListView().getContext(),
list);
setListAdapter(adapter);
} else {
//refill the adapter
((CardAdapter) getListView().getAdapter()).refill(list);
}
int i = 0;
for (final ParseObject card : mCards) {
ParseQuery<ParseObject> likesQuery = mCardsLikeRelation.getQuery();
likesQuery.whereEqualTo("objectId", card.getObjectId());
final int finalI = i;
likesQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> likes, ParseException e) {
if (e == null) {
//list returned - look for a match
Log.e(TAG, "likes" + likes.size());
if (likes.size() == 1) {
//liked
list.get(finalI).setSelected(true);
}
} else {
Log.e(TAG, e.getMessage());
}
}
});
i++;
}
} else {
Log.d(TAG, "Error: " + e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
builder.setMessage(e.getMessage())
.setTitle(R.string.error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
private CardModel get(String title, String content, String background, boolean background_image, int likes) {
return new CardModel(title, content, background, background_image, likes);
}
}
Got it.
In the second query fetching likes by user i used
likesQuery.find();
Instead of
likesQuery.findInBackground(new FindCallback<ParseObject>() {});

Retrieving files on Parse - Images

I have already managed to store image files into parse. My question lies in retrieving it. In the sense that in the registration process users are asked to upload a profile picture, and where the image is later stored into parse as an image. My issue lies in retrieving it, where along with pulling information like name, headline, age for a potential match, I also want to be able to retrieve the picture.
Below is the code, where I retrieve string information, but where I would want to retrieve files as well.
public class MatchingActivity extends Activity {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);
logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
query.whereGreaterThanOrEqualTo("Minimum_Age", minimumAge).whereGreaterThanOrEqualTo("Age", userage);
query.whereLessThanOrEqualTo("Maximum_Age", maximumAge).whereLessThanOrEqualTo("Age", userage);
// query.whereWithinKilometers("Maximum_Distance", point, maxDistance)
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());
names.add(userList.get(i).get("Age").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
If you have any question, if like it.
Update
Image code
ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");
//call the function
displayImage(image, image_expert);
//and here is the function
private void displayImage(ParseFile thumbnail, final ImageView img) {
if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null) {
Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);
}
} else {
Log.e("paser after downloade", " null");
}
}
});
} else {
Log.e("parse file", " null");
// img.setImageResource(R.drawable.ic_launcher);
img.setPadding(10, 10, 10, 10);
}
}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
activity code
public class Fragment1 extends Fragment {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container, false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
//query.whereGreaterThanOrEqualTo("Age", minimumAge);
//query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).get("Name").toString());
names.add(userList.get(i).get("Headline").toString());
ParseFile image = (ParseFile) userData.getParseFile("ProfilePicture");
//call the function
displayImage(image, image_expert);
//and here is the function
private void displayImage(ParseFile thumbnail, final ImageView img) {
if (thumbnail != null) {
thumbnail.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null) {
Log.e("parse file ok", " null");
img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
(display.getWidth() / 5),
(display.getWidth() /50), false));
img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
img.setPadding(10, 10, 0, 0);
}
} else {
Log.e("paser after downloade", " null");
}
}
});
} else {
Log.e("parse file", " null");
// img.setImageResource(R.drawable.ic_launcher);
img.setPadding(10, 10, 10, 10);
}
}
names.add(userList.get(i).get("Age").toString());
names.add(userList.get(i).get("ActivityName").toString());
// names.add(userList.get(i).getParseObject("ProfilePicture").;
}
usersListView = (ListView)getActivity().findViewById(R.id.userlistview);
namesArrayAdapter =
new ArrayAdapter<String>(getActivity().getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity().getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Issues on the following line
private void displayImage(ParseFile thumbnail, final ImageView img) {
Multiple markers at this line
- Syntax error on token ",", ;
expected
- Syntax error on token "(", ;
expected
- Syntax error on token ")", ;
expected
see if something like below would help:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.fetchInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseFile file = (ParseFile)object.get("image");
if(file != null){
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if(bitmap != null){
imageAccount.setImageBitmap(bitmap);
}else{
Log.d(TAG, "file null?");
}
} else {
Log.d(TAG, "ParseFile ParseException: " + e.toString());
}
}
});
}else{
Log.d(TAG, "ParseFile is null");
}
} else {
Log.d(TAG, "ParseException: " + e.toString());
}
}
});
When you store a pointer to type 'file' in parse, u get a URL and a name .
Anytime you have reference to the file, you should be able to also get the URL.
Use the URL to do an async get and to generate a local bitmap for using the photo in a view.

Formatting errors - issues with code formation

I have experienced various minor errors with forming my code, and is having difficulty resolving them.
In particular, I have the following line underline with the following message
query.findInBackground(new FindCallback<ParseObject>() {
The method findInBackground(FindCallback<ParseUser>) in the type ParseQuery<ParseUser> is not applicable for the arguments (new FindCallback<ParseObject>(){})
As well as errors closing my statements.
and finally
Below is the complete code
Any help would be greatly appreciated. Thanks in advance
Update:
Updated code
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
ParseQuery<ParseObject> queryo = ParseQuery.getQuery("User");
queryo.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
queryo.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
queryo.whereEqualTo("Looking_Gender", userGender);
queryo.setLimit(1);
queryo.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
queryo.orderByDescending("Name");
queryo.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> object, ParseException e) {
// TODO Auto-generated method stub
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView()
.findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to
// be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(
R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length
+ ", or exception: " + e.getMessage());
}
}};
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done1(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
Update 2
a few formating issues such as
1) object cannot be resolved
public class Fragment1 extends Fragment {
public interface Constants {
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser().getString("Gender");
String activityName = ParseUser.getCurrentUser().getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser().getNumber(
"Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser().getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> users,ParseException e) {
// Do whatever you need to extract object from "users"
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
}
});
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistname, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistname.size(); i++) {
names.add(userlistname.get(i).get("Name").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userlistheadline, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistheadline.size(); i++) {
headline.add(userlistheadline.get(i).get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done2(List<ParseUser> userlistage, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistage.size(); i++) {
age.add(userlistage.get(i).get("Age").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
query.findInBackground(new FindCallback<ParseUser>() {
public void done3(List<ParseUser> userlistactivity, ParseException e) {
if (e == null) {
for (int i = 0; i < userlistactivity.size(); i++) {
activityname.add(userlistactivity.get(i)
.get("ActivityName").toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
This should be a start:
public class Fragment1 extends Fragment
{
public interface Constants
{
String LOG = "com.dooba.beta";
}
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ArrayList<String> age;
private ArrayList<String> headline;
private ArrayList<String> activityname;
private ArrayList<Images> alProfilePicture;
private ListView usersListView;
private Button logoutButton;
String userGender = ParseUser.getCurrentUser()
.getString("Gender");
String activityName = ParseUser.getCurrentUser()
.getString("ActivityName");
Number maxDistance = ParseUser.getCurrentUser()
.getNumber("Maximum_Distance");
String userLookingGender = ParseUser.getCurrentUser()
.getString("Looking_Gender");
Number minimumAge = ParseUser.getCurrentUser()
.getNumber("Minimum_Age");
Number maximumAge = ParseUser.getCurrentUser()
.getNumber("Maximum_Age");
Number userage = ParseUser.getCurrentUser()
.getNumber("Age");
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setConversationsList();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment1_layout, container,
false);
return view;
}
private void setConversationsList()
{
currentUserId = ParseUser.getCurrentUser()
.getObjectId();
names = new ArrayList<String>();
age = new ArrayList<String>();
headline = new ArrayList<String>();
activityname = new ArrayList<String>();
alProfilePicture = new ArrayList<Images>();
// String userActivitySelectionName = null;
ParseQuery<ParseUser> query = ParseUser.getQuery();
// query.whereEqualTo("ActivityName",userActivitySelectionName);
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1);
query.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
query.orderByDescending("Name");
Log.d(Constants.LOG, "");
ParseQuery<ParseObject> queryo = ParseQuery.getQuery("User");
queryo.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
queryo.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
queryo.whereEqualTo("Looking_Gender", userGender);
queryo.setLimit(1);
queryo.whereEqualTo("ActivityName", activityName);
// query.whereGreaterThanOrEqualTo("Age", minimumAge);
// query.whereLessThanOrEqualTo("Age", maximumAge);
queryo.orderByDescending("Name");
queryo.findInBackground(new FindCallback<ParseObject>()
{
#Override
public void done(List<ParseObject> object, ParseException e)
{
// TODO Auto-generated method stub
ParseFile image = object.getParseFile("ProfilePicture");
ParseImageView imageView = (ParseImageView) getView()
.findViewById(R.id.profilePictureResult);
// The placeholder will be used before and during the fetch, to
// be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(
R.drawable.profile_pict));
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback()
{
#Override
public void done(byte[] data, ParseException e)
{
Log.i("ParseImageView",
"Fetched! Data length: " + data.length
+ ", or exception: " + e.getMessage());
}
});
}
query.findInBackground(new FindCallback<ParseUser>()
{
public void done (List < ParseUser > userlistname, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistname.size(); i++)
{
names.add(userlistname.get(i)
.get("Name")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
names);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
public void done1(List<ParseUser> userlistheadline, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistheadline.size(); i++)
{
headline.add(userlistheadline.get(i)
.get("Headline")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistheadline);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_all,
headline);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done2(List<ParseUser> userlistage, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistage.size(); i++)
{
age.add(userlistage.get(i)
.get("Age")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistage);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
age);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
public void done3(List<ParseUser> userlistactivity, ParseException e)
{
if(e == null)
{
for(int i = 0; i < userlistactivity.size(); i++)
{
activityname.add(userlistactivity.get(i)
.get("ActivityName")
.toString());
}
usersListView = (ListView) getActivity().findViewById(
R.id.userlistactivityname);
namesArrayAdapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), R.layout.user_list_item,
activityname);
usersListView.setAdapter(namesArrayAdapter);
usersListView
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a,
View v, int i, long l)
{
openConversation(names, i);
}
});
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error loading user list", Toast.LENGTH_LONG)
.show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos)
{
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("Name", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>()
{
public void done(List<ParseUser> user, ParseException e)
{
if(e == null)
{
Intent intent = new Intent(getActivity()
.getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0)
.getObjectId());
startActivity(intent);
}
else
{
Toast.makeText(getActivity().getApplicationContext(),
"Error finding that user", Toast.LENGTH_SHORT)
.show();
}
}
});
}
}

Parse whereEqualTo

I am trying to retrieve information from parse. In particular, I have added a condition where it would only return the list of users that have selected the same activity.
I have tried the below code, but it does seem to work, as that condition returns an empty list.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName","");
It would essentially see which users have selected that particular activity name and return
Below is the entire code
public class MatchingActivity extends Activity {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);
logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName",userActivitySelectionName);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).getUsername().toString());
}
usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Thanks in advance.
Double-check in the Data Browser, but I'm guessing that the column has "undefined" instead of an empty string.
In this case you'll need to use the following:
query.whereDoesNotExist("ActivityName");
The whereDoesNotExist() and whereExists() functions are for checking if there is any value set on a column.

cannot be resolved to a variable - Parse.com

I am trying to retrieve information from parse. In particular, I have added a condition where it would only return the list of users that have selected the same activity. In doing so, I unexpectedly receive the following error:
userActivitySelectionName cannot be resolved to a variable
It would essentially see which users have selected that particular activity name and return I randomly added this variable because I would like to retrieve the list of usersname who have selected that activity with the exception of the currentuser. I did not want to specificly point out a username since the list changes all the time, so was thinking of having a generic variable name such as userActivitySelectionName
Below is the entire code
public class MatchingActivity extends Activity {
private String currentUserId;
private ArrayAdapter<String> namesArrayAdapter;
private ArrayList<String> names;
private ListView usersListView;
private Button logoutButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matching);
logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
setConversationsList();
}
private void setConversationsList() {
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName",userActivitySelectionName);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> userList, ParseException e) {
if (e == null) {
for (int i=0; i<userList.size(); i++) {
names.add(userList.get(i).getUsername().toString());
}
usersListView = (ListView)findViewById(R.id.usersListView);
namesArrayAdapter =
new ArrayAdapter<String>(getApplicationContext(),
R.layout.user_list_item, names);
usersListView.setAdapter(namesArrayAdapter);
usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int i, long l) {
openConversation(names, i);
}
});
} else {
Toast.makeText(getApplicationContext(),
"Error loading user list",
Toast.LENGTH_LONG).show();
}
}
});
}
public void openConversation(ArrayList<String> names, int pos) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", names.get(pos));
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> user, ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Error finding that user",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Thanks in advance.
You have missed to declare this variable userActivitySelectionName. You need to declare this variable and assign the datatype, which is going to store.
say
String userActivitySelectionName = null;
As #Suresh said, You need to make a check of null value before you make any operations on it like
if(userActivitySelectionName!=null)
query.whereEqualTo("ActivityName",userActivitySelectionName);
Otherwise, you will get NullPointerException when you invoke methods or access properties of a null value.
If the value is null, you can set a meaningful value instead of null say empty string "" for a String variable

Categories

Resources