更新用户数据时出错:com.parse.ParseRequest $ ParseRequestException:i / o失败

时间:2016-03-20 10:21:13

标签: android exception parse-platform

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("appchatid")
            .clientKey("appclientid")
            .server("http://localhost:1337/parse/")   // '/' important after 'parse'
            .build());

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.

    //defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);

    Log.i("Parse", "onCreate: ");
    ParseObject testObject = new ParseObject("TestApple");
    testObject.put("foo", "11234");

    testObject.saveInBackground(new SaveCallback() {
          @Override
          public void done(com.parse.ParseException e) {
              if (e == null) {
                  // Saved successfully.
                  Log.d("TEST", "User data saved!");
              } else {
                  // The save failed.
                  Log.d("TEST", "Error updating user data: " + e);
              }
          }
      });
  }
}

这是代码。当我运行它时,我收到错误。

  

更新用户数据时出错:   com.parse.ParseRequest $ ParseRequestException:i / o失败

1 个答案:

答案 0 :(得分:0)

主要问题是您没有连接到服务器。 [1]-确保已在清单

中添加了应用程序ID和客户端ID
<meta-data
            android:name="com.parse.SERVER_URL"
            android:value="https://parseapi.back4app.com" />
        <meta-data
            android:name="com.parse.APPLICATION_ID"
            android:value="_App_Id_Here_" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="_client_Key_here_" />

[2]-将repositories { maven { url 'https://jitpack.io' } }添加到您的build.gradle(Project:xyz)

[3]-确保您将.server字段更改为您的解析服务器,例如:“ https://parseapi.back4app.com”为

applicationId("appchatid")
            .clientKey("appclientid")
            .server("https://parseapi.back4app.com")  <-- this line is changed
            .build());