Skip to content Skip to sidebar Skip to footer

Error In Doinbackground Method

I am testing an app to retrieve data to my listview from parse.com I have no errors in my code but on running the app closes saying 'unfortunately app has stopped' This is my log c

Solution 1:

EDIT: Change your onCreate method in MainActivity.java

@OverrideprotectedvoidonCreate(Bundle savedInstanceState)
{
    // TODO: Implement this methodsuper.onCreate(savedInstanceState);

    setContentView(R.layout.listview_main);
Parse.initialize(this, "9MoehuvnUJRKcvF8SL3nbW0slHHJNPJU4ONXGcD5", "kmBoHM4iwdm0YiyeR7aoMlyMgC5oh1oyTIOt34iu");

        ParseUser.enableAutomaticUser();
        ParseACLdefaultACL=newParseACL();

        // If you would like all objects to be private by default, remove this line.
        defaultACL.setPublicReadAccess(true);

        ParseACL.setDefaultACL(defaultACL, true);

    newRemoteDataTask().execute();

}

This is the error:

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

You need to call Parse.initialize(context, oauthKey, oauthSecret) in your application before you make any queries to Parse. This tells the service which app is yours. You can find the keys on your Parse Dashboard.

This blog post might be helpful: http://www.michaelevans.org/blog/2013/08/14/tutorial-building-an-android-to-do-list-app-using-parse/

Solution 2:

You forgot to add your application class to your AndroidManifest.xml.

<application name="com.mycompany.myapp.ParseApplication"

You should also remove the Parse.initialize() method call in your Activity, and add it back to your application class.

Solution 3:

look at there is typo in spell of country

@OverrideprotectedVoid doInBackground(Void... params) {
        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                "Country");
        query.orderByDescending("_created_at");
        try {
            ob = query.find();
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        returnnull;
    }

Solution 4:

As of reading your logcat log, it seems that this is your actual error:

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

As stated in

08-2715:30:33.610: E/AndroidRuntime(558): FATAL EXCEPTION: AsyncTask #108-2715:30:33.610: E/AndroidRuntime(558): java.lang.RuntimeException: An error occured while executing doInBackground()
08-2715:30:33.610: E/AndroidRuntime(558):      at android.os.AsyncTask$3.done(AsyncTask.java:278)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-2715:30:33.610: E/AndroidRuntime(558):      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.lang.Thread.run(Thread.java:856)
08-2715:30:33.610: E/AndroidRuntime(558): Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseUser.checkApplicationContext(ParseUser.java:853)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseUser.getCurrentUser(ParseUser.java:726)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseUser.getCurrentSessionToken(ParseUser.java:756)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.findFromNetworkAsync(ParseQuery.java:520)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.access$200(ParseQuery.java:77)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery$4.runOnNetworkAsync(ParseQuery.java:436)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.runCommandWithPolicyAsync(ParseQuery.java:383)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.findWithCachePolicyAsync(ParseQuery.java:447)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery$6.call(ParseQuery.java:492)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery$6.call(ParseQuery.java:490)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:643)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.parse.ParseQuery.find(ParseQuery.java:490)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.example.parselistview.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:51)
08-2715:30:33.610: E/AndroidRuntime(558):      at com.example.parselistview.MainActivity$RemoteDataTask.doInBackground(MainActivity.java:1)
08-2715:30:33.610: E/AndroidRuntime(558):      at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-2715:30:33.610: E/AndroidRuntime(558):      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-2715:30:33.610: E/AndroidRuntime(558):      ... 5 more

It's always recommended to check your error log from the top down, starting by fixing the first error it reports. As for this particular one, take a look at https://parse.com/docs/android/guide#getting-started

Post a Comment for "Error In Doinbackground Method"