简体   繁体   English

创建ParseObject时java android i/o失败异常

[英]java android i/o Failure Exception when creating a ParseObject

I started a Parse server instance on AWS where I want to store my data from an android application.我在 AWS 上启动了一个 Parse 服务器实例,我想在其中存储来自 android 应用程序的数据。

In the module's gradle I inserted the below under dependencies在模块的 gradle 中,我在依赖项下插入了以下内容

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

and created a new application which initializes parse configuration并创建了一个初始化解析配置的新应用程序

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);

    }
}

This is all new to me and I am following a 3-year-old course on Android development.这对我来说是全新的,我正在学习一个 3 年前的 Android 开发课程。 when I run this, the exception keeps getting caught with the same error:当我运行它时,异常不断被捕获,并出现相同的错误:

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

My android Manifest looks like this:我的 android 清单如下所示:

<?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>

Where is the error coming from?错误来自哪里? how can it be solved?如何解决?

The Main problem is that you are not connecting to the server.主要问题是您没有连接到服务器。

[1]-make sure you have added your application id and client id in AndroidManifest [1]-确保您已在AndroidManifest添加您的应用程序 ID 和客户端 ID

**change _App_Id_here and _Client_key_here with your keys something like "ISIGDGU4YGCE673". **使用您的密钥更改 _App_Id_here 和 _Client_key_here,例如“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]- add repositories { maven { url 'https://jitpack.io' } } to your build.gradle(Project:xyz) [2]- 将存储库{ maven { url 'https://jitpack.io' } }到您的build.gradle(Project:xyz)

[3]- make sure u change the.server field to your parse server, AppId and clientKey: [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()
        );

get those keys from your server's dashboard settings -> keys从服务器的仪表板设置中获取这些密钥 -> 密钥

This problem can also occur in case your hosted parse server is on HTTP server rather than on HTTPS.如果您的托管解析服务器在 HTTP 服务器上而不是在 HTTPS 上,也会出现此问题。 Because Android 9.0 and above will not let you use clear text information over the HTTP.因为Android 9.0 及以上不会让你通过HTTP 使用明文信息。 So if it is the case then you can do the following:因此,如果是这种情况,那么您可以执行以下操作:

  • In you manifest file, and in your manifest tag add the android:targetSandboxVersion="1" line.在您的清单文件中,并在您的清单标签中添加android:targetSandboxVersion="1"行。 So it will look like所以它看起来像
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
   android:targetSandboxVersion="1">
  • In your manifest file, in application tag add the android:usesCleartextTraffic="true" line.在清单文件中,在应用程序标签中添加android:usesCleartextTraffic="true"行。 So it will look like所以它看起来像
<application
        android:name=".Example"
        android:allowBackup="true"
        ....
        android:usesCleartextTraffic="true">

Fixed.固定的。 For some reason the Parse server dashboard which comes from the AWS service.出于某种原因,来自 AWS 服务的 Parse 服务器仪表板。 That is for example, http://ec2-18-220-53-0.us-east-2.compute.amazonaws.com doesnt have an apps category, You'd notice it only shows my Bitnami Parse API without an apps option.例如, http: //ec2-18-220-53-0.us-east-2.compute.amazonaws.com 没有应用程序类别,您会注意到它只显示我的 Bitnami Parse API 而没有应用程序选项。 This means firstly, you're not able to pass data to any app on the server which should be available.这意味着首先,您无法将数据传递到服务器上应该可用的任何应用程序。 Secondly, connecting the server to your android app would not work as the Master key is actually now different from the Client key in recent times.其次,将服务器连接到您的 android 应用程序将无法正常工作,因为主密钥现在实际上与最近的客户端密钥不同。

Instead of AWS use Back4App which would work the same exact way.而不是 AWS 使用 Back4App,它的工作方式完全相同。 Back4App is a scalable back-end service based on the Parse Server Platform. Back4App 是基于 Parse Server Platform 的可扩展后端服务。

Pros:优点:

You dont need to use an SSH client to connect to server and retrieve your APP ID, Client Key or server url.您无需使用 SSH 客户端连接到服务器并检索您的 APP ID、客户端密钥或服务器 url。 Everything is under server setting on the dashboard.一切都在仪表板上的服务器设置下。

Proceed to Back4App:继续 Back4App:

Step 1: Create an Account on back4app第 1 步:在 back4app 上创建一个帐户

Step 2: Create an App, you can name it instagramandroid based on this tutorial第2步:创建一个应用程序,您可以根据本教程将其命名为instagramandroid

Step 3: follow all the remaining info in the link here and every thing should work fine .第 3 步:按照此处链接中的所有剩余信息进行操作,一切都应该正常工作。 https://www.back4app.com/docs/pages/android/how-to-build-an-android-app-on-back4app https://www.back4app.com/docs/pages/android/how-to-build-an-android-app-on-back4app

Note: When adding the parse dependency, the latest one is 1.17.3.注意:添加解析依赖时,最新的是1.17.3。 which would work very fine unless you may want to use 1.20.0, i tried it and doesn't really work.除非您可能想使用 1.20.0,否则它会工作得很好,我试过了,但并没有真正起作用。 Add it like you'll normally add a dependency in your gradle file : 'implementation com.parse:parse-android:1.17.3'添加它,就像您通常在 gradle 文件中添加依赖项一样:'implementation com.parse:parse-android:1.17.3'

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

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