繁体   English   中英

从Android Studio将数据(解析启动器)保存到heroku时,为什么会出现“保存失败”的提示?

[英]Why do I get a “Save Failed” when saving data (Parse Starter) from Android Studio to heroku?

我已经下载了Parse Starter Project ,并将Parse Starter Project从此处直接部署到Heroku(我使用了“ Deploy to Heroku”按钮)。

在Heroku内部,一切都很好。 我进行了测试,没有任何问题(我什至看到“我梦想成为一个网站”)。

当我在Android Studio中启动应用程序并使用手机(三星Galaxy S6)或模拟器时,我总是会收到消息“保存失败”。

Android Studio 2.2.3中的输出

我在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);
}

为什么我不能将数据保存到heroku-我的错误在哪里?

所有密钥都通过“复制和粘贴”被放入代码中,并且仅在此问题中不可读!

期待您的回答和帮助!

更新:heroku CLI日志:2016-12-10T15:13:07.221288 + 00:00 app [web.1]:未捕获的内部服务器错误。 {错误:连接ECONNREFUSED 127.0.0.1:27017 2016-12-10T15:13:07.221299 + 00:00应用程序[web.1]:在export._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 [作为oncomplete](net.js:1085:14)2016-12-10T15:13:07.221303 + 00:00 app [web.1]:名称:'MongoError',2016-12-10T15:13:07.221304 +00:00 app [web.1]:消息:'connect ECONNREFUSED 127.0.0.1:27017'}错误:connect ECONNREFUSED 127.0.0.1:27017 2016-12-10T15:13:07.221305 + 00:00 app [web.1 ]:在Object.exports._errnoException(util.js:1026:11)2016-12-10T15:13:07.221305 + 00:00 app [web.1]:在export._exceptionWithHostPort(util.js:1049:20) 2016-12-10T15:13:07.221306 + 00:00 app [web.1]:位于TCPConnectWrap.afterConnect [作为未完成](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

27017是Mongo的默认端口,您是否将Mongo插件添加到了heroku应用程序?

我有这个问题。 如果确定您的应用程序ID,主密钥和服务器正确,则可能是您遇到了同样的问题,并且您的应用程序未正确链接到数据库。

遵循这些步骤

  1. 下载并安装包括命令行界面在内的heroku工具带
  2. 打开一个cmd提示符(或非Windows操作系统的等效终端),然后输入heroku login,在弹出的浏览器中登录heroku,然后您应该会在终端提示符中看到“以YourUserName@EmailAddress.com登录”,
  3. 输入heroku config:set DATABASE_URI=*link到在heroku设置下的配置vars上标记为MONGODB_URI MongoDB的config:set DATABASE_URI=*link *,然后是-a NameOfAppToAssociateWithDatabaseHere ,然后按Enter。

再次运行您的项目,这一次您的日志应该显示Save Succeeded。 然后,您可以在heroku中打开应用程序的资源,在资源中打开数据库,然后在collections下查看其中包含的对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM