gpt4 book ai didi

创建 ParseObject 时出现 java android i/o Failure Exception

转载 作者:行者123 更新时间:2023-12-02 01:39:03 31 4
gpt4 key购买 nike

我在 AWS 上启动了一个 Parse 服务器实例,我想在其中存储来自 Android 应用程序的数据。

在模块的 gradle 中,我在依赖项下插入了以下内容

implementation 'com.parse.bolts:bolts-tasks:1.4.0'
implementation 'com.parse:parse-android:1.17.3'

并创建了一个初始化解析配置的新应用程序

import android.app.Application;

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 StarterApp 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(myAppId)
.clientKey(myClientKey)
.server(serverAddress)
.build()
);

ParseObject object = new ParseObject("ExampleObject");
// object.put("id", "123");
// object.put("name", "jack");



object.saveInBackground(new SaveCallback () {
@Override
public void done(ParseException ex) {
if (ex == null) {
Log.i("Parse Result", "Successful!");
} else {
Log.i("Parse Result", "Failed" + ex.toString());
}
}
});


ParseUser.enableAutomaticUser();

ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);

}
}

这对我来说是全新的,我正在学习 3 年的 Android 开发类(class)。当我运行这个时,异常不断被捕获并出现相同的错误:

com.parse.ParseRequest$ParseRequestException: i/o failure

我的 Android list 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parsetest2">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:name=".StarterApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

错误从何而来?怎么解决?

最佳答案

主要问题是您没有连接到服务器。

[1]-确保您已在 AndroidManifest 中添加应用程序 ID 和客户端 ID

**将 _App_Id_here 和 _Client_key_here 更改为您的 key ,例如“ISIGDGU4YGCE673”。

<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_" /> //<- put your key
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="_client_Key_here_" /> //<- put your key

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

[3]- 确保将 .server 字段更改为解析服务器、AppId 和 clientKey:

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId(myAppId)//"myAppId" should be sth like ->"ASHWD63787EDXSG8"
.clientKey(myClientKey)//should be sth like ->"tdf29yedih287823"
.server(serverAddress)//something like-> "https://parseapi.back4app.com"
.build()
);

从服务器的仪表板设置 -> 键中获取这些 key

关于创建 ParseObject 时出现 java android i/o Failure Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54743209/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com