带有AWS Analytic Integration的Android应用无法读取awsconfiguration.json

时间:2018-09-05 19:15:23

标签: java android amazon-web-services android-studio

我正在学习教程here

我只是想尝试一下Android开发和AWS集成。我在this guide之后设置了基本的helloworld Android应用。然后继续在第一个链接中添加AWS组件。

当我进入“ Monitor Analytics”部分时,我的项目将构建,但在运行时会引发异常。

例外情况如下:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxxx.wearables_data_receiver.app/com.xx.xxxx.wearables_data_receiver.feature.MainActivity}: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
    at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:99)
    at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:83)
    at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:68)
    at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:45)
    at com.amazonaws.mobile.client.AWSMobileClient.initialize(AWSMobileClient.java:155)
    at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)
    at android.app.Activity.performCreate(Activity.java:6237)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1351)
    at android.content.res.Resources.openRawResource(Resources.java:1265)
    at android.content.res.Resources.openRawResource(Resources.java:1241)
    at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:88)

该行:

at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)

在第一个链接中指向教程中的“ AWSMobileClient.getInstance()。initialize”调用:

AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
        @Override
        public void onComplete(AWSStartupResult awsStartupResult) {
            System.out.println("AWSMobileClient is instantiated and you are connected to AWS!");
        }
    }).execute();

我不确定这里发生了什么,我尝试打开文件权限,并将其放置在几个不同的目录中,但无济于事。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

该错误是由于缺少awsconfiguration.json文件。

 Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.

您可以确保将awsconfiguration.json文件放置在res/raw目录中并且具有有效的json吗?如果您使用Amplify CLI进行设置,则应始终使用所需信息自动更新awsconfiguration.json文件。