我从json响应中得到一个值,我需要将其发送到另一个片段以使用它。
public void onResponse(Call<String> call, Response<String> response) {
if (response.isSuccessful()) {
if (response.body() != null) {
Log.i("Responsestring", response.body().toString());
Log.i("onSuccess", response.body().toString());
String jsonresponse = response.body().toString();
try {
JSONObject jsonObject = new JSONObject(jsonresponse);
if (jsonObject.getString("status").equals("success")) {
JSONObject jsonData = jsonObject.getJSONObject("data");
Integer id = jsonData.getInt("id");
Log.i("ID", String.valueOf(id));
Toast.makeText(getActivity(), "Login Successfully!", Toast.LENGTH_SHORT)
.show();
Intent intent;
intent = new Intent(getActivity(), ActivityListEvents.class);
startActivity(intent);
Log.i("DATA", jsonObject.getString("data"));
Bundle bundle = new Bundle();
bundle.putInt("id", id);
Log.i("ID BUNDEL", String.valueOf(id));
Profile_Fragment mFragment_B = new Profile_Fragment();
mFragment_B.setArguments(bundle);
}
} catch (JSONException e) {
e.printStackTrace();
}
这里,我正在获取我需要的值,我使用捆绑包将其发送到配置文件片段。
我的个人资料片段
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.profile_fragment, container, false);
initViews();
setListeners();
Bundle bundle = getArguments();
int id = bundle.getInt("id");
Log.i("ID REC",String.valueOf(id));
return view;
}
我需要id才能在updateUsers中调用它
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(UpdateProfile.UPDPRO)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
UpdateProfile api = retrofit.create(UpdateProfile.class);
Call<String> call = api.UpdateUsers(id,name,prenom,adresse,email,numtel);
收到此错误消息
'空对象引用上的'int android.os.Bundle.getInt(java.lang.String)'
我已经搜索了问题,但没有解决。
我首先看到您的代码,您必须将数据传递到
问题已解决