Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
CSS
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:
Java
@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);

            //check for wi-fi or 3G
            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);

                // Execute RemoteDataTask AsyncTask
//                new ViewDataTask().execute();

                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"); //group by shopid

                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();
//                                    Log.d("BEFORE", username);

                                    if (username.equals(ParseUser.getCurrentUser().getUsername())) {
//                                        Log.d("you are IN", username);

                                        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()); //send photo
                                                            }
                                                        }

                                                        searchlist.add(result);
                                                    } else {
                                                        Log.d("Error", e.getMessage());
                                                    }
                                                    proDialog.hide();
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
        return convertView;
    }
Posted
Updated 23-Apr-15 4:59am
v3
Comments
Sergey Alexandrovich Kryukov 23-Apr-15 11:51am    
What do you mean by a "pointer to an object"? Java does not have pointers, but has references, reference types...
—SA
marialena93 23-Apr-15 12:20pm    
Yes I know about java. I mean a pointer of Parse.com database. That kind of pointer returns NULL
Richard MacCutchan 23-Apr-15 11:55am    
Quote: rate.getParseObject("name"); returns null ...

So you need to use your debugger to find out why it is returning null, rather than an object.
marialena93 24-Apr-15 6:23am    
How do you suggest to do it? Because about debugging the only way that I check usually my programs is through Log.d() . But right now I can't seem to find anything that will help me to do. So, I am stuck.
Richard MacCutchan 24-Apr-15 6:37am    
Well I am afraid that the only way to diagnose the problem is to use the debugger to find out why that variable is null. There is no way we can guess just from looking at the code, as it will depend on where all the information is coming from.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900