0

I'm trying to query a parse.com table based on the value of a string variable and not a string..

The below works and is an example of what is being searched for.

query.whereEqualTo("movieCategory", "Action");

But instead of this I've stored a variable from a Spinner..

query.whereEqualTo("movieCategory", derrick);

I can access this variable just fine from other methods.. except the parse query

Imagine the variable "derrick" contains another string such as "Thriller"

Any ideas on how I can achieve this instead of being constrained to what i specifically want to search for?

The application crashes and complains of a "android.view.WindowLeaked:"

Will I need to do it as if derrick.equals("action") else if derrick.equals("romance") etc...? because when I tried that the same crash occured.

Thanks in advance

EDIT

This is my DashboardActivity.class where I'm getting the variable...

public String getCategory() {
        Spinner spinCategory = (Spinner) findViewById(R.id.spin_category);
        String whatCategory = spinCategory.getSelectedItem().toString();

        return whatCategory;
    }

Here is the whole try method from the ResultsActivity.class

// RemoteDataTask AsyncTask
    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(ResultsActivity.this);
            // Set progressdialog title
            mProgressDialog.setTitle("");
            // Set progressdialog message
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {

            DashboardActivity  cls2= new DashboardActivity();
            cls2.getCategory();
            String derrick = cls2.getCategory();

            // Create the array
            movielist = new ArrayList<movieListGroup>();

            try {
                // Locate the class table named "Movie" in Parse.com
                ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                        "Movie");

                query.whereEqualTo("movieCategory", derrick);

//                if (derrick.equals ("Action")) {
//                    query.whereEqualTo("movieCategory", "Action");
//
//                } else if (derrick.equals ("Romance")) {
//                    query.whereEqualTo("movieCategory", "Romance");
//
//                } else if (derrick.equals("Comedy")) {
//                    query.whereEqualTo("movieCategory", "Comedy");
//
//                }

                //query.whereEqualTo("movieCategory", "Romance");
                query.orderByAscending("movieNum");

                ob = query.find();
                for (ParseObject movie : ob) {
                    // Locate images in flag column
                    ParseFile image = (ParseFile) movie.get("movieImage");

                    movieListGroup map = new movieListGroup();
                    map.setNumber((String) movie.get("movieNum"));
                    map.setCategory((String) movie.get("movieCategory"));
                    map.setTitle((String) movie.get("movieTitle"));
                    map.setDescription((String) movie.get("movieDesc"));
                    map.setDirector((String) movie.get("movieDirector"));
                    map.setFlag(image.getUrl());
                    movielist.add(map);
                }
            } catch (ParseException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listview);
            // Pass the results into ListViewAdapter.java
            adapter = new ListViewAdapter(ResultsActivity.this,
                    movielist);
            // Binds the Adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();
        }
    }

And the log cat.....

03-13 17:40:52.575    5980-5980/com.example.derrick.moveed E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.derrick.moveed.ResultsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{339cf210 V.E..... R.....ID 0,0-1026,288} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
            at android.app.Dialog.show(Dialog.java:298)
            at com.example.derrick.moveed.ResultsActivity$RemoteDataTask.onPreExecute(ResultsActivity.java:77)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
            at android.os.AsyncTask.execute(AsyncTask.java:535)
            at com.example.derrick.moveed.ResultsActivity.onCreate(ResultsActivity.java:61)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-13 17:40:59.376    5980-6003/com.example.derrick.moveed I/Process﹕ Sending signal. PID: 5980 SIG: 9
11
  • I do not think android.view.WindowLeaked crashes the app. It is probably something else that is causing the crash Commented Mar 13, 2015 at 17:10
  • @hoomi Maybe you're right but if i search directly for a string like "Action" my function works.. Commented Mar 13, 2015 at 17:16
  • @ci_ "derrick" is a variable that contains the value of a spinner from the previous activity. I can access it just fine in other methods too. Commented Mar 13, 2015 at 17:17
  • 1
    try using derrick+"" instead? it force it translate into a string Commented Mar 13, 2015 at 17:28
  • can you post your logcat. Commented Mar 13, 2015 at 17:36

2 Answers 2

1

You can't just instantiate an Activity with new and then use findViewById(). If your AsyncTask is part of your Activity you should be able to call DashboardActivity.this. getCategory() instead.

Just saw that there is another Activity involved that your not showing and I'm not sure how ResultActivity is started from DashboardActivity. You may have to pass the category as an extra when you start ResultActivity.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this some it helped me i also faced the same error.

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
     ProgressDialog mProgressDialog ;
    Context c;
     public RemoteDataTask(Context c){
    this.c =c;
    }
     @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(ResultsActivity.this);
                // Set progressdialog title
    ........
    }

    }

Now on calling this task :

new RemoteDataTask(MainActivity.this).execute();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.