Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将值从片段传递到另一个错误_Java_Android_Json - Fatal编程技术网

Java 将值从片段传递到另一个错误

Java 将值从片段传递到另一个错误,java,android,json,Java,Android,Json,我从一个json响应中得到了一个值,我需要将它发送到另一个片段来使用它 public void onResponse(Call<String> call, Response<String> response) { if (response.isSuccessful()) { if (response.body() != null) {

我从一个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();
                            }
我需要身份证才能在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);
reformation-reformation=new-reformation.Builder()
.baseUrl(UpdateProfile.UPDPRO)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
UpdateProfile api=reformation.create(UpdateProfile.class);
Call Call=api.UpdateUsers(id、name、prenom、address、email、numtel);
我得到这个错误

空对象引用上的“intandroid.os.Bundle.getInt(java.lang.String)”


我已经搜索了这个问题,但没有解决它。

因为我首先看到了您的代码,所以您必须将数据传递到

  Intent  intent = new Intent(getActivity(), 
   ActivityListEvents.class);
 intent.putExtras("yourKey",""+yourvalue)     
 startActivity(intent);
在此之后,将数据获取到ActivityListEvents中,如果片段从ActivityListEvents开始,则调用此函数

  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);
问题解决

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if(bundle != null)
        {
            id = bundle.getInt("id");
        }
        bundle.putInt("id", id);
        Log.i("IDFROM ",String.valueOf(id));

        Bundle bundle1 = new Bundle();
        bundle1.putInt("id",id);
        final Profile_Fragment fragobj = new Profile_Fragment();
        fragobj.setArguments(bundle1);
我的碎片

Bundle bundle = this.getArguments();
        int id = bundle.getInt("id");

您可以添加错误登录吗?如果两个片段都在同一活动的viewpager中,那么您必须将该值传递给父活动,然后传递给另一个片段java.lang.NullPointerException:尝试调用虚拟方法“int android.os.Bundle.getInt(java.lang.String)”在androidx.Fragment.app.Fragment.performCreateView(Fragment.java:2600)的com.example.toutPartner.Profile_Fragment.onCreateView(Profile_Fragment.java:41)上的空对象引用上为什么要启动活动,然后执行片段事务?参数也设置为fragment,但缺少片段事务?我不太理解您,我应该写
Bundle Bundle=new Bundle();bundle.putInt(“id”,id);Log.i(“ID BUNDEL”,String.valueOf(ID));Profile_Fragment mffragment_B=新的Profile_Fragment();mFragment_B.setArguments(bundle)在我的ActivityList或我的个人资料片段profile_片段中加载此片段,我指的是activityin ActivityListEvent`受保护的void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_list_events);logout=findViewById(R.id.logout);update=findViewById(R.id.update);update.setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v){fragmentManager=getSupportFragmentManager();fragmentManager.beginTransaction().replace(R.id.frameContainer,new Profile_Fragment()).commit();})`是的,首先您必须将此数据从第一个活动传递到第二个活动,然后从第二个活动将数据传递到片段,而不是其工作了解活动->活动列表事件->配置文件\u片段所以我需要在活动列表事件中使用捆绑包?
Bundle bundle = this.getArguments();
        int id = bundle.getInt("id");