I am trying to retrieve data from Parse.com. I have one object called `Shop_ratings` and one object called `Shop`.
The first one has a pointer called `name` that points to the `name` field of the second one.
I want, to take info from both `Shop` and `Shop_Ratings` objects.
The conditions are to choose rows from `Shop_Ratings` that has as pointer in `username` attribute the one as the Current User's and I want to take info from `Shop`'s rows that has the same `name` pointer , which means that they both represent the same Shop.
PROBLEM:
The problem is that this line: rate.getParseObject("name");
returns null, so I can't continue and retrieve any data from the object that this attribute points to.
So if i try to do this: shop.getObjectId();
without the if (shop==null)
it throws a NullPointerException
This is my Logcat from the start of the application launch in my phone till right after I click the button to do the things below in my code:
04-23 17:58:29.608 6446-6446/guide_me_for_all.guide_me_for_all I/Choreographer﹕ Skipped 115 frames! The application may be doing too much work on its main thread.
04-23 17:58:29.778 6446-6446/guide_me_for_all.guide_me_for_all I/Choreographer﹕ Skipped 41 frames! The application may be doing too much work on its main thread.
04-23 17:58:32.240 6446-6446/guide_me_for_all.guide_me_for_all I/Timeline﹕ Timeline: Activity_launch_request id:guide_me_for_all.guide_me_for_all time:1963180
04-23 17:58:32.450 6446-6446/guide_me_for_all.guide_me_for_all I/Choreographer﹕ Skipped 44 frames! The application may be doing too much work on its main thread.
04-23 17:58:32.691 6446-6446/guide_me_for_all.guide_me_for_all I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@421d7110 time:1963634
04-23 17:58:32.811 6446-6446/guide_me_for_all.guide_me_for_all D/SHOP:﹕ pointer is null
This is my whole code of the fragment's onCreateView:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
proDialog = CustomProgressDialog.ctor(this.getActivity());
if (convertView == null) {
convertView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_userpreviousratings, container, false);
if (isConnected() == null || isConnected().isEmpty() || isConnected().equals("No Connection")) {
Intent intentVibrate = new Intent(getActivity().getApplicationContext(), VibrateService.class);
getActivity().startService(intentVibrate);
String text = "Please enable your Wi-fi or 3G connection, close completely the application and re-open the application!";
int duration = Toast.LENGTH_LONG;
Toast.makeText(this.getActivity().getApplicationContext(), (CharSequence) text, duration).show();
getActivity().finish();
} else {
if (isConnected() == "3G") {
Intent intentVibrate = new Intent(getActivity().getApplicationContext(), VibrateService.class);
getActivity().startService(intentVibrate);
String text = "The application is going to use the 3G connection(Extra cost)! Prefer Wi-Fi connection if it is possible! - Close completely the application and re-open it!";
int duration = Toast.LENGTH_LONG;
Toast.makeText(this.getActivity().getApplicationContext(), (CharSequence) text, duration).show();
}
final ImageButton lessinfo = (ImageButton) convertView.findViewById(R.id.lessinfo);
proDialog.show();
searchlist = new ArrayList<SetUserPreviousRatingsConditions>();
Parse.initialize(this.getActivity(), "hoMaKMBh80zY26VI4SDe6iEbWD3Congh7z32KgJl", "wWV193mEtPqHto5ZcmN6IOpBp0GTH2QQlC3tf1vz");
ParseQuery query = new ParseQuery("Shop_ratings");
query.include("name");
query.include("username");
query.orderByDescending("createdAt");
query.addDescendingOrder("name");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> rateList, ParseException e) {
if (e == null) {
if (rateList.size() == 0) {
Log.d("PROBLEM", "SIZE = 0");
proDialog.hide();
} else if (rateList.size() > 0) {
for (ParseObject rate : rateList) {
ParseUser user = rate.getParseUser("username");
String username = user.getUsername();
if (username.equals(ParseUser.getCurrentUser().getUsername())) {
flag_show = true;
final SetUserPreviousRatingsConditions result = new SetUserPreviousRatingsConditions();
result.setRating(String.valueOf(rate.getInt("overall_rating")));
result.setDate(rate.getUpdatedAt());
result.setRate_pricing(String.valueOf(rate.getInt("rating_pricing")));
result.setRate_cleaning(String.valueOf(rate.getInt("rating_cleaning")));
result.setRate_qos(String.valueOf(rate.getInt("rating_QOS")));
result.setRate_valueformoney(String.valueOf(rate.getInt("rating_value_for_money")));
result.setRate_variety(String.valueOf(rate.getInt("rating_variety")));
result.setRate_reserv(String.valueOf(rate.getInt("rating_reservations")));
result.setRate_decor(String.valueOf(rate.getInt("rating_decoration")));
ParseObject shop = rate.getParseObject("name");
if (shop == null) {
Log.d("SHOP:", "pointer is null");
proDialog.hide();
}
else {
String shopid = shop.getObjectId();
if (shopid != null) {
Log.d("shop id: ", String.valueOf(shopid));
} else {
Log.d("shop id is null", "");
}
final ParseQuery<ParseObject> shop_rate = ParseQuery.getQuery("Shop");
shop_rate.getInBackground(shopid, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
shopname = object.getString("name");
result.setShopName(String.valueOf(shopname));
Log.d("shopname: ", String.valueOf(shopname));
if (object.getParseFile("photo") != null) {
ParseFile image = (ParseFile) object.getParseFile("photo");
if (image.getUrl() != null) {
result.setImage(image.getUrl());
}
}
searchlist.add(result);
} else {
Log.d("Error", e.getMessage());
}
proDialog.hide();
}
});
}
}
}
}
}
}
});
}
}
return convertView;
}