创建ParseObject时,java android i/o失败异常 [英] java android i/o Failure Exception when creating a ParseObject

查看:94
本文介绍了创建ParseObject时,java android i/o失败异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I started a Parse server instance on AWS where I want to store my data from an android application.

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

In the module's gradle I inserted the below under dependencies

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

    }
}

这对我来说是全新的,而且我正在学习为期3年的Android开发课程.当我运行此命令时,该异常会不断出现相同的错误:

This is all new to me and I am following a 3-year-old course on Android development. when I run this, the exception keeps getting caught with the same error:

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

我的Android清单看起来像这样:

My android Manifest looks like this:

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

推荐答案

如果您托管的解析服务器位于HTTP服务器而不是HTTPS上,也会发生此问题.因为Android 9.0及更高版本不允许您通过HTTP使用明文信息.因此,如果是这种情况,则可以执行以下操作:

This problem can also occur in case your hosted parse server is on HTTP server rather than on HTTPS. Because Android 9.0 and above will not let you use clear text information over the HTTP. So if it is the case then you can do the following:

  • 在清单文件中的清单标签中,添加android:targetSandboxVersion="1"行.这样看起来就像
  • In you manifest file, and in your manifest tag add the android:targetSandboxVersion="1" line. So it will look like
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
   android:targetSandboxVersion="1">

  • 在清单文件的application标签中,添加android:usesCleartextTraffic="true"行.这样看起来就像
    • In your manifest file, in application tag add the android:usesCleartextTraffic="true" line. So it will look like
    • <application
              android:name=".Example"
              android:allowBackup="true"
              ....
              android:usesCleartextTraffic="true">
      

      这篇关于创建ParseObject时,java android i/o失败异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆