[英]Android Studio Error : Cannot resolve symbol CreateTodoInput and CreateTodoMutation
I am trying to build an Android app using AWS Amplify CLI.我正在尝试使用 AWS Amplify CLI 构建一个 Android 应用程序。
I am following the AWS documentation .我正在关注AWS 文档。 However, I am getting this error, in Android Studio:
但是,我在 Android Studio 中收到此错误:
Cannot resolve symbol CreateTodoInput and CreateTodoMutation
无法解析符号 CreateTodoInput 和 CreateTodoMutation
I have pasted all the dependencies as present in the documentation in my app and project Gradle files.我已将所有依赖项粘贴到我的应用程序和项目 Gradle 文件中的文档中。
I found a similar question ( Can not resolve symbol CreateTodoInput ), but the answer provided doesn't resolve my issue.我发现了一个类似的问题(无法解析符号 CreateTodoInput ),但提供的答案并没有解决我的问题。
My entire code is in MainActivity.java
:我的整个代码在
MainActivity.java
:
package com.example.testamplify;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.amazonaws.mobile.config.AWSConfiguration;
import com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient;
import com.apollographql.apollo.GraphQLCall;
import com.apollographql.apollo.exception.ApolloException;
import javax.annotation.Nonnull;
public class MainActivity extends AppCompatActivity {
private AWSAppSyncClient mAWSAppSyncClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAWSAppSyncClient = AWSAppSyncClient.builder()
.context(getApplicationContext())
.awsConfiguration(new AWSConfiguration(getApplicationContext()))
.build();
runMutation();
}
public void runMutation() {
CreateTodoInput createTodoInput = CreateTodoInput.builder()
.name("Use AppSync")
.description("Realtime and Offline")
.build();
mAWSAppSyncClient
.mutate(CreateTodoMutation.builder()
.input(createTodoInput).build()
)
.enqueue(mutationCallback);
}
private GraphQLCall.Callback<CreateTodoMutation.Data> mutationCallback =
new GraphQLCall.Callback<CreateTodoMutation.Data>() {
@Override
public void onResponse(@Nonnull Response<CreateTodoMutation.Data> response) {
Log.i("Results", "Added Todo");
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Log.e("Error", e.toString());
}
};
}
将我的项目与 gradle 文件同步解决了这个问题!
I had the same problem as I'm new and experimenting with this too.我有同样的问题,因为我是新手,也在试验这个。 I think CreateTodo is a type of variable.
我认为 CreateTodo 是一种变量。 Download this example of an android app provided by AWS, found here .
下载 AWS 提供的 Android 应用程序示例,可在此处找到。 Open the ListEventsActivity, on line 77. You will see this same code, hope it helps you understand, it helped me.
打开 ListEventsActivity,在第 77 行。你会看到同样的代码,希望它帮助你理解,它帮助了我。
Retry the tutorial again, and when you use amplify add api
, after amplify push.再次重试教程,当你使用
amplify add api
,在 amplify push 之后。
It'll ask the follow Do you want to generate code for your newly created GraphQL API
.它会询问
Do you want to generate code for your newly created GraphQL API
。 At first i choose no, and the folder graphql was not generated.起初我选择不,并且没有生成文件夹graphql。
So, when the prompt ask所以,当提示询问时
Do you want to generate code for your newly created GraphQL API
You have to answer yes and configure with the default values.您必须回答是并使用默认值进行配置。
At least, that was wrong wit me, give it a try.至少,我错了,试一试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.