简体   繁体   English

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

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

I've downloaded Parse Starter Project and deployed the Parse Starter Project directly from here to Heroku (I used the button "Deploy to Heroku"). 我已经下载了Parse Starter Project ,并将Parse Starter Project从此处直接部署到Heroku(我使用了“ Deploy to Heroku”按钮)。

Inside Heroku everything is fine. 在Heroku内部,一切都很好。 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". 当我在Android Studio中启动应用程序并使用手机(三星Galaxy S6)或模拟器时,我总是会收到消息“保存失败”。

Output in Android Studio 2.2.3 Android Studio 2.2.3中的输出

I use the following code in StarterApplication.java : 我在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? 为什么我不能将数据保存到heroku-我的错误在哪里?

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. 更新:heroku CLI日志:2016-12-10T15:13:07.221288 + 00:00 app [web.1]:未捕获的内部服务器错误。 { 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= {错误:连接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 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应用程序?

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. 如果确定您的应用程序ID,主密钥和服务器正确,则可能是您遇到了同样的问题,并且您的应用程序未正确链接到数据库。

Following these steps 遵循这些步骤

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

Run your project again and this time your log should say Save Succeeded. 再次运行您的项目,这一次您的日志应该显示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. 然后,您可以在heroku中打开应用程序的资源,在资源中打开数据库,然后在collections下查看其中包含的对象。

暂无
暂无

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

相关问题 如何从Android Studio将复杂数据保存在Firebase中? - How do I save complex data in firebase from android studio? 为什么将Web服务中的JSON数据解析为android时会得到空值? - why i get null value when i parse JSON data from web service into android? 为什么保存图片时会出错? - Why do I get an error when saving an image? Android Studio:为什么我只运行最简单的代码就会出错 - Android studio: why do I get errors when I just run the simplest code 当我设置背景图像时,为什么在 android studio 中会出现此错误 - Why do i get this error in android studio when i set a background image 当我添加第三方依赖时,我无法解决android studio中的错误,该怎么办才能解决此问题? - When I add 3rd party dependencies I get failed to resolve errors in android studio, what should I do to fix this? 为什么在运行 Flutter Android 应用程序时出现“清单合并失败并出现多个错误”错误? - Why do I get "Manifest merger failed with multiple errors" error when running Flutter Android app? 具有子类,Android的ParseQueryAdapter为什么我不能从Parse取回数据? - ParseQueryAdapter with Subclasses, android Why can't I get my data back from Parse? 当我在 Android Studio 中使用数据绑定时,我会收到什么错误 Smart cast to 'HomeViewModel' is possible? - What do I get the error Smart cast to 'HomeViewModel' is impossible when I use data binding in Android Studio? 为什么在 Android Studio 中尝试构建 cordova 应用程序时出现此错误 - Why do i get this error when trying to build cordova app in Android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM