-1

I have 5 activities namely- D_EngNameScreen, D_LocNameScreen,D_GenCharScreen,D_PathSNameScreen and Disease_InformationScreen. Here the first four activities are sending extras through Intent and Bundle to the last activity (Disease_InformationScreen). The codes are-

// from the D_EngNameScreen activity

  Intent intentDENG = new Intent(D_EngNameScreen.this, Disease_InformationScreen.class);
    d_eng_Name_Bundle.putString("CROPNAME_EN",crop_en);
    d_eng_Name_Bundle.putString("DENGNAME",d_EngName );
    intentDENG.putExtra("NAVIGATIONTYPE","EnglishName");
    intentDENG.putExtras(d_eng_Name_Bundle);
    startActivity(intentDENG);


//from the D_LocNameScreen activity

    Intent intentDLN = new Intent(D_LocNameScreen.this, Disease_InformationScreen.class);
    d_local_name_bundle.putString("CROPNAME_LN",crop_ln);
    d_local_name_bundle.putString("DLOCALNAME",d_Locname);
    intentDLN.putExtra("NAVIGATIONTYPE","LocalName");
    intentDLN.putExtras(d_local_name_bundle);
    startActivity(intentDLN);

 //from the D_GenCharScreen activity

Intent intentDGENCHAR = new Intent(D_GenCharScreen.this, Disease_InformationScreen.class);
    d_gen_char_bundle.putString("CROPNAME_GC",crop_gc);
    d_gen_char_bundle.putString("SPREADMODE",d_spread_Items);
    d_gen_char_bundle.putString("PATHOGENCONENV",d_patho_environ_Items);
    intentDGENCHAR.putExtra("NAVIGATIONTYPE","GeneralChar");
    intentDGENCHAR.putExtras(d_gen_char_bundle);
    startActivity(intentDGENCHAR);


//from the D_PathSNameScreen activity

Intent intentDPSN = new Intent(D_PathSNameScreen.this,Disease_InformationScreen.class);
        d_pathoName_bundle.putString("CROPNAME_PN",crop_pn);
    d_pathoName_bundle.putString("DPATHOSCINAME",d_pathosci_name);
    intentDPSN.putExtra("NAVIGATIONTYPE","PathogenName");
    intentDPSN.putExtras(d_pathoName_bundle);
    startActivity(intentDPSN);

I am receiving the extras in the Disease_InformationScreen activity-

  if (getIntent().getExtras() != null) {
              if (getIntent().getStringExtra("NAVIGATIONTYPE").contentEquals("EnglishName")) {
            Bundle getcrop = getIntent().getExtras();
            cropname_en = getcrop.getString("CROPNAME_EN");
            Log.d("CNAME: ", cropname_en);

            d_EngName = getcrop.getString("DENGNAME");
            Log.d("DENGNAME: ", d_EngName);
            danme12.setText(d_EngName);

        } else if (getIntent().getStringExtra("NAVIGATIONTYPE").contentEquals("LocalName")) {
            Bundle getcrop = getIntent().getExtras();
            cropname_ln = getcrop.getString("CROPNAME_LN");
            Log.d("CNAME: ", cropname_ln);
            d_LocName = getcrop.getString("DLOCALNAME");

        } else if (getIntent().getStringExtra("NAVIGATIONTYPE").contentEquals("PathogenName")) {
            Bundle getcrop = getIntent().getExtras();
            cropname_pn = getcrop.getString("CROPNAME_PN");
            d_PathName = getcrop.getString("DPATHOSCINAME");

        } else if (getIntent().getStringExtra("NAVIGATIONTYPE").contentEquals("GeneralChar")) {
            Bundle getcrop = getIntent().getExtras();
            cropname_gc = getcrop.getString("CROPNAME_GC");
            d_SprdMode = getcrop.getString("SPREADMODE");
            d_PathCE = getcrop.getString("PATHOGENCONENV");
        }
    }

In this case the D_EngNameScreen activity is successfully sending extras to the Disease_InformationScreen activity, but the remaining are not doing the same. Its showing null pointer exception at -

d_local_name_bundle.putString("CROPNAME_LN",crop_ln);//for example

in the three remaining acivities while sending the extras to the Disease_InformationScreen acivity. The Logcat is-

05-20 11:40:27.365 15619-15619/com.thesiswork.ashraf.ashrafresearchwork E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                      java.lang.NullPointerException
                                                                                          at com.thesiswork.ashraf.ashrafresearchwork.D_LocNameScreen.onClick(D_LocNameScreen.java:123)
                                                                                          at android.view.View.performClick(View.java:4212)
                                                                                          at android.view.View$PerformClick.run(View.java:17476)
                                                                                          at android.os.Handler.handleCallback(Handler.java:800)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:100)
                                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:5371)
                                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                          at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                                                                                          at dalvik.system.NativeStart.main(Native Method)

So please help me in this problem

1 Answers1

0

I think you didn't create the object of

d_local_name_bundle

Shubham
  • 521
  • 4
  • 11
  • You were right @Shubham. I have checked that i found that i had forget to create object of the Bundle variables in the remaining three activities. It solved my problem. Thanks a lot. – Md Ashraful Haque May 20 '16 at 07:09
  • if it was useful then please mark it so it can improve my points dude – Shubham May 20 '16 at 07:12