我正在使用AWS API Gateway和AWS Lambda.在尝试部署API时,我经常会遇到此类错误消息.错误消息表示选择部署阶段.但我仍然选择并尝试部署!但同样的错误发生!
在这个API中,我有多个具有多种方法的资源.以前我成功地以相同的方式部署这个相同的API.但现在我无法部署它.
请有人帮我修理它.另外:我不使用AWS CLI工具,只使用AWS Web仪表板.
我正在尝试User通过POSTAndroid 的方法将类对象(使用 Gson-Retrofit)发送到服务器。如果服务器收到任何数据,它将向 App 发送一个 JSON 对象,其中包含“成功”和“消息”密钥。但不幸的是每次服务器发送{"success":false,"message":"No"}向 App。
我认为从 MainActivity 调用该方法时有问题。为了更好地理解我的所有代码如下:
MainActivity.java我调用这个方法: private void checkUserValidity(User userCredential){
ApiInterface apiInterface = RetrofitApiClient.getClient().create(ApiInterface.class);
Call<ValidityResponse> call = apiInterface.getUserValidity(userCredential);
call.enqueue(new Callback<ValidityResponse>() {
@Override
public void onResponse(Call<ValidityResponse> call, Response<ValidityResponse> response) {
ValidityResponse validity = response.body();
Toast.makeText(getApplicationContext(), validity.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的ApiInterface.java班级是:
public interface ApiInterface {
@POST("/retrofit_login/login.php")
Call<ValidityResponse> getUserValidity(
@Body User userLoginCredential);
}
Run Code Online (Sandbox Code Playgroud)
RetrofitApiClient.java 类是: …
我附上了 3 个DialogFragment. 在这个对话框中,我想显示一个RecyclerView. 当对话框打开时,前 2 个项目的宽度会缩小。但是当第三个项目出现时稍微滚动后,它以预期的宽度显示[检查截图1和2]。如果我继续从上到下滚动,那么我会看到其余的项目正常显示。然后我再次从底部滚动到顶部,令人惊讶地注意到第 1 项和第 2 项也按预期显示。
[检查截图编号。3]
我想分享我的代码。
从我的适配器类:
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
return new CustomViewHolder(view);
}
Run Code Online (Sandbox Code Playgroud)
项目.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:id="@+id/modalityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/modalityTitle"
tools:text="X-Ray"
android:textSize="22sp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<ImageView
android:id="@+id/statusImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/modalityTextView"
app:layout_constraintBottom_toBottomOf="@id/modalityTextView"
app:layout_constraintRight_toRightOf="parent"
android:src="@drawable/ic_remove_circle_outline_black_24dp"/>
<TextView
android:id="@+id/contrastTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/modalityTextView"
app:layout_constraintLeft_toLeftOf="parent"
android:text="@string/contrast"
android:textStyle="bold"
android:layout_marginTop="4dp"/>
<TextView
android:id="@+id/contrastTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) android android-dialogfragment android-recyclerview android-constraintlayout
我有一个JSONArray.我想将其解析为JSONObject.所以Loop和try-catch是必须的.
愚蠢的问题是:我应该在TRY中使用FOR循环还是反向?真的是重要还是两者都一样?
请告诉我最佳实践(如果两者不相同).
try {
for(i=0; i<jsonArray.length(); i++){
jsonObject = jsonArray.getJSONObject(i);
//do something
}
} catch (JSONException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
for(i=0; i<jsonArray.length(); i++){
try {
jsonObject = jsonArray.getJSONObject(i);
//do something
} catch (JSONException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
哪个更好?