все.Я использую работу с ящиками, изменяя содержимое с помощью фрагментов, поэтому есть PerfilFragment , например:
public class PerfilFragment extends Fragment {
final CurrentView currentView = new CurrentView();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_perfil, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getActivity() != null) {
getActivity().setTitle(R.string.menu_perfil);
final CognitoCachingCredentialsProvider credentialsProvider;
if (getContext() != null) {
AWSConfiguration awsConfig = new AWSConfiguration(getContext());
credentialsProvider = new CognitoCachingCredentialsProvider(
getContext(),
awsConfig
);
currentView.setCredentialsProvider(credentialsProvider);
currentView.setView(view);
final FloatingActionButton fab = view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Insert().doInBackground(currentView);
}
});
}
}
}
}
Тип CurrentView также является внутренним классом.как Вставить класс:
class CurrentView {
private CognitoCachingCredentialsProvider credentialsProvider;
private View view;
CognitoCachingCredentialsProvider getCredentialsProvider() {
return credentialsProvider;
}
void setCredentialsProvider(CognitoCachingCredentialsProvider credentialsProvider) {
this.credentialsProvider = credentialsProvider;
}
View getView() {
return view;
}
void setView(View view) {
this.view = view;
}
}
class Insert extends AsyncTask<CurrentView, Void, Table> {
private final static String TABLE = "perfil";
@Override
protected Table doInBackground(CurrentView... currentView) {
AmazonDynamoDBClient dbClient;
try {
dbClient = new AmazonDynamoDBClient(currentView[0].getCredentialsProvider());
Table perfilTable = Table.loadTable(dbClient, TABLE);
Document perfilDocument = new Document();
final EditText perfilNome = currentView[0].getView().findViewById(R.id.perfil_nome_txt);
final EditText perfilDataNasc = currentView[0].getView().findViewById(R.id.perfil_datanasc_txt);
final EditText perfilGenero = currentView[0].getView().findViewById(R.id.perfil_genero_txt);
perfilDocument.put("userId", currentView[0].getCredentialsProvider().getCachedIdentityId());
perfilDocument.put("nome", perfilNome.getText().toString());
perfilDocument.put("datanasc", perfilDataNasc.getText().toString());
perfilDocument.put("genero", perfilGenero.getText().toString());
Document perfilInserido = perfilTable.putItem(perfilDocument);
if (perfilInserido.containsKey("genero")) {
DynamoDBEntry perfilInseridoGenero = perfilInserido.get("genero");
if (perfilInseridoGenero != null) {
if (perfilInseridoGenero.asString().equals(perfilGenero.getText().toString())) {
Snackbar
.make(
currentView[0].getView(),
"Perfil atualizado!",
Snackbar.LENGTH_LONG
)
.setAction("Atualizar", null)
.show();
}
}
}
return perfilTable;
} catch (Exception e) {
Log.e("EXCEPTION", e.getMessage(), e);
return null;
}
}
}
Исключение выдается в методе doInBackground , в строке: Table perfilTable = Table.loadTable(dbClient, TABLE);
Чего мне не хватает