0
votes

I've downloaded Parse Starter Project and deployed the Parse Starter Project directly from here to Heroku (I used the button "Deploy to Heroku").

Inside Heroku everything is fine. I tested without any problems (I even saw "I dream of being a website").

When I start my app in Android Studio and use either my phone (Samsung Galaxy S6) or the emulator I always get back the message "Save failed".

Output in Android Studio 2.2.3

I use the following code in StarterApplication.java:

package com.parse.starter;

import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.parse.SaveCallback;

public class StarterApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Add your initialization code here
    Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId("applicationId")
        .clientKey("clientKey")
        .server("https://nameofapp.herokuapp.com/parse/")
        .build()
    );

    ParseObject gameScore = new ParseObject("GameScore");
    gameScore.put("score", 1337);
    gameScore.put("playerName", "Sean Plott");
    gameScore.put("cheatMode", false);
    gameScore.saveInBackground(new SaveCallback() {
        public void done(ParseException e) {
            if (e == null) {
                Log.i("Parse", "Save Succeeded");
            } else {
                Log.i("Parse", "Save Failed");
            }
        }
    });

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
}

Why can't I save the data to heroku - where is my mistake?

All keys are put into the code via Copy & Paste and are only unreadable within this question!

Looking forward to your answers and help!

UPDATE: heroku CLI Log: 2016-12-10T15:13:07.221288+00:00 app[web.1]: Uncaught internal server error. { Error: connect ECONNREFUSED 127.0.0.1:27017 2016-12-10T15:13:07.221299+00:00 app[web.1]: at exports._exceptionWithHostPort (util.js:1049:20) 2016-12-10T15:13:07.221299+00:00 app[web.1]: at Object.exports._errnoException (util.js:1026:11) 2016-12-10T15:13:07.221302+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14) 2016-12-10T15:13:07.221303+00:00 app[web.1]: name: 'MongoError', 2016-12-10T15:13:07.221304+00:00 app[web.1]: message: 'connect ECONNREFUSED 127.0.0.1:27017' } Error: connect ECONNREFUSED 127.0.0.1:27017 2016-12-10T15:13:07.221305+00:00 app[web.1]: at Object.exports._errnoException (util.js:1026:11) 2016-12-10T15:13:07.221305+00:00 app[web.1]: at exports._exceptionWithHostPort (util.js:1049:20) 2016-12-10T15:13:07.221306+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14) 2016-12-10T15:13:07.230326+00:00 heroku[router]: at=info method=POST path="/parse/classes/GameScore" host=XXXXXXXXXXXX.herokuapp.com request_id=ca250458-621a-4749-bae9-6882208ae7ba fwd="62.226.173.93" dyno=web.1 connect=0ms service=3ms status=500 bytes=531

2
check logs heroku logs via terminal, or if you have a dashboard check logs there - lxknvlk
Thanks a lot for your help - I get this ouptut (I think it's a problem of connecting to the DB, but I can't solve it) - the log is in my main question - myyvee

2 Answers

0
votes

27017 is the default port of Mongo, did you add the Mongo addon to the heroku app?

0
votes

I had this problem. If you're sure your application ID, master key and server are correct then it's likely you have the same problem I did and your application isn't properly linked to the database.

Following these steps

  1. Download and install the heroku tool belt including the command line interface
  2. Open a cmd prompt (or equivalent terminal for non-Windows OS) and type heroku login, log in to heroku within the browser that pops up and you should then see "logged in as [email protected]" in the terminal prompt,
  3. Enter heroku config:set DATABASE_URI=*link to MongoDB found in heroku settings under config vars tagged MONGODB_URI goes here* followed by -a NameOfAppToAssociateWithDatabaseHere and hit enter.

Run your project again and this time your log should say Save Succeeded. Then you can open resources of the application in heroku, open the database within resources and see your object contained in it under collections.