[英]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 遵循这些步骤
YourUserName@EmailAddress.com
" in the terminal prompt, YourUserName@EmailAddress.com
登录”, 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. 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.