作者:琪琪 | 来源:互联网 | 2023-09-24 23:31
我正在尝试获取将用于显示我要访问的属性值的当前订单ID,但它返回null。我使用断点检查,但是this.orderItem.jobOrder.id有一个值。
这是我在activity.class中的代码,在其中我从另一个活动中获得Bundle Extras。
OrderItem是一个对象类。
public class TrackOrderactivity extends Baseactivity implements TrackOrderactivityView {
@Inject
ApiController apiController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_track_order);
toolbarShowWithClose(null);
this.presenter = new TrackOrderactivityPresenter(view,this.apiController);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
this.orderItem = new Gson().fromJson(bundle.getString("OrderItem"),OrderItem.class);
apiController.getJobOrderByIdWithInclude(this.orderItem.jobOrder.id,"checkout,shop,discounts,deliverables.replacement,job-order-fmcg-campaign-vouchers",new Callbacklistener.SingleEntityListener() {
@Override
public void onSuccess(Object data,List included) {
final Entity jobOrder = (Entity) data;
List include = AppUtil.cast(included);
final Entity shop = AppUtil.getEntity(jobOrder.relationships.shop.data.id,AppUtil.getEntitiesByType("shops",AppUtil.cast(included)));
final List discounts = AppUtil.getEntitiesByType("discounts",AppUtil.cast(included));
final List deliverables = AppUtil.getEntitiesByType("deliverables",AppUtil.cast(included));
final List campaigns = AppUtil.getEntitiesByType("job-order-fmcg-campaign-vouchers",AppUtil.cast(included));
tv_subtotal.setText(orderItem.jobOrder.attributes.purchased_deliverables_amount_in_cents);
}
@Override
public void onFailed(Object object) {
}
});
}
}}
这是我的ApiController.class代码。
public void getJobOrderByIdWithInclude(String jobOrderId,String include,Callbacklistener.SingleEntityListener listener) {
String token = !StringUtil.isnullOrBlank(Preferences.getString(Prefkey.session_token)) ? Preferences.getString(Prefkey.session_token) : Preferences.getString(Prefkey.session_temporary_token);
final Call feed = apiService.get_job_order_by_id(String.format("Token %s",token),jobOrderId,include);
feed.enqueue(new retrofit2.Callback() {
@Override
public void onResponse(@NonNull Call call,@NonNull Response response) {
if (listener != null) {
if (response.isSuccessful()) {
SingleEntityResponse body = response.body();
if (body != null) {
listener.onSuccess(body.data,Arrays.asList(body.included));
} else {
listener.onFailed(response);
}
} else {
listener.onFailed(response);
}
}
}
@Override
public void onFailure(@NonNull Call call,@NonNull Throwable t) {
if (listener != null) {
listener.onFailed(t);
}
}
});
}
这是我的ApiService.java
@GET("job-orders/{id}")
Call get_job_order_by_id(
@Header("Authorization") String header,@Path("id") String id,@Query("include") String include);
我的logcat返回此错误。