-4

I'm new at android programming, I want to fetch Parse in ListView arrangement and i found the perfect guide, but i cant really implement it on my code. I have browse a lot for 2 days and i give up.

Here's the error

E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.example.osbert.buttons, PID: 2732
java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:300)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
        at com.parse.ParseUser.checkApplicationContext(ParseUser.java:1426)
        at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:1048)
        at com.parse.ParseUser.access$900(ParseUser.java:27)
        at com.parse.ParseUser$9.then(ParseUser.java:1041)
        at com.parse.ParseUser$9.then(ParseUser.java:1038)
        at com.parse.TaskQueue.enqueue(TaskQueue.java:61)
        at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:1038)
        at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:1001)
        at com.parse.ParseQuery.getUserAsync(ParseQuery.java:352)
        at com.parse.ParseQuery.access$1600(ParseQuery.java:78)
        at com.parse.ParseQuery$15.call(ParseQuery.java:1000)
        at com.parse.ParseQuery$15.call(ParseQuery.java:997)
        at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:936)
        at com.parse.ParseQuery.findInBackground(ParseQuery.java:997)
        at com.parse.ParseQuery.find(ParseQuery.java:588)
        at com.example.osbert.buttons.RestaurantList$RemoteDataTask.doInBackground(RestaurantList.java:60)
        at com.example.osbert.buttons.RestaurantList$RemoteDataTask.doInBackground(RestaurantList.java:34)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)

            

E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.osbert.buttons.RestaurantList has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{27bb5583 V.E..... R......D 0,0-729,322} 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.osbert.buttons.RestaurantList$RemoteDataTask.onPreExecute(RestaurantList.java:46)
        at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
        at android.os.AsyncTask.execute(AsyncTask.java:535)
        at com.example.osbert.buttons.RestaurantList.onCreate(RestaurantList.java:30)
        at android.app.Activity.performCreate(Activity.java:5937)
        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)

And here's my code

package com.example.osbert.buttons;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;

public class RestaurantList extends Activity {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewAdapter adapter;
private List<WorldPopulation> worldpopulationlist = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from listview_main.xml
    setContentView(R.layout.listview_main);
    // Execute RemoteDataTask AsyncTask
    new RemoteDataTask().execute();
}

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

    @Override
    protected Void doInBackground(Void... params) {
        // Create the array
        worldpopulationlist = new ArrayList<WorldPopulation>();
        try {
            // Locate the class table named "Country" in Parse.com
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "Country");
            // Locate the column named "ranknum" in Parse.com and order list
            // by ascending
            query.orderByAscending("ranknum");
            ob = query.find();
            for (ParseObject country : ob) {
                // Locate images in flag column
                ParseFile image = (ParseFile) country.get("flag");

                WorldPopulation map = new WorldPopulation();
                map.setRank((String) country.get("rank"));
                map.setCountry((String) country.get("country"));
                map.setPopulation((String) country.get("population"));
                map.setFlag(image.getUrl());
                worldpopulationlist.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(RestaurantList.this,
                worldpopulationlist);
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
        finish();

    }
}

}

Pls help :((

Thanks in advance

  • The error message is clear: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library. – molnarm May 04 '15 at 09:19
  • possible duplicate of http://stackoverflow.com/questions/5181508/activity-has-leaked-window-com-android-internal-policy-impl-phonewindowdecorvie?rq=1 and http://stackoverflow.com/questions/12000940/android-activity-has-leaked-window-com-android-internal-policy-impl-phonewindow?rq=1 please refer them – Aniruddha K.M May 04 '15 at 09:19
  • Yes i have check those thread. unfortunately i have no lead there :( – osbert intanu May 04 '15 at 12:12
  • Hi, i have found the solution. turns out that i misplaced the :name on the manifest. Thanks for your help :D – osbert intanu May 04 '15 at 12:58

2 Answers2

1

Have you even tried resolving this?

Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library?

Its the cause of the crash.

Also why are you calling finish() i onPostExecute?! It will close your activity...and i suppose you would like to see the results in your list view?

JanBo
  • 2,925
  • 3
  • 23
  • 32
0

U error Logs says the solution.....

Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library. at com.parse.ParseUser.checkApplicationContext(ParseUser.java:1426)

Gowtham Raj
  • 2,915
  • 1
  • 24
  • 38
  • Yes, I have call the parse on the other java class. Should I put on my current activity? But where? If I put it inside the onCreate then it lead to alot of error. – osbert intanu May 04 '15 at 12:06