title: How to pass data to navigation drawer item?
body: <p><strong>I am using a nav drawer</strong> with three items(Time sheet, claims, project) and I would like to pass <code>ab</code> to claims. In time sheet I have 3 activities, the <code>ab</code> is in the work_details activity.How can I do to achieve this? </p>
  
  <p>TimeSheet has 3 activities (Information(extend to fragment),work force,work details)</p>
  
  <p>Claims has 2 activities(claims(extend to fragment), cameraMain).</p>
  
  <p><strong>WorkDetails.java</strong></p>
  
  <pre><code>  Button btn1 = (Button) findViewById(R.id.button2);
    btn1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View arg0) {
                  AlertDialog.Builder builder = new AlertDialog.Builder(WorkDetailsTable.this);
                  builder.setTitle("Data Saved");
                  builder.setMessage("Are you sure you want to save?");
                  builder.setIcon(android.R.drawable.ic_dialog_alert);
                  builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int ii) {
                  long ab = ts.insertTimeSheet(name, weather, date, status,b,i);         
                 Bundle bundle =new Bundle();
                 bundle.putString("ab","ab");
                 Claims o=new Claims();
                 o.setArguments(bundle);
  }
  </code></pre>
  
  <p><strong>Claims.java</strong></p>
  
  <pre><code>final Long fk=this.getArguments().getLong("ab");
   Button button = (Button) claims.findViewById(R.id.button8);
  button.setOnClickListener(new View.OnClickListener() {
              public void onClick(View arg0) {
                  Intent intent = new Intent(getActivity().getApplicationContext(), CameraMain.class);
                  Toast.makeText(getActivity().getApplicationContext(), fk+"", Toast.LENGTH_LONG).show();
                  startActivity(intent);
              }
          });
          return claims;
      }
  </code></pre>
  
  <p>I refer from <a href="https://stackoverflow.com/questions/12739909/send-data-from-activity-to-fragment-in-android">Send data from activity to fragment in android</a> but the app crashed when I select claims item.</p>
  
  <blockquote>
    <p>11-02 09:25:55.910    6116-6116/com.example.project.project
    E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.example.project.project, PID: 6116
        java.lang.NullPointerException
                at com.example.project.project.Claims.onCreateView(Claims.java:59)
                at android.app.Fragment.performCreateView(Fragment.java:1700)
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
                at android.app.BackStackRecord.run(BackStackRecord.java:684)
                at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)</p>
  </blockquote>
  
  <p>I think the NullPointException is came from here</p>
  
  <blockquote>
    <p>fk=data.getLong("ab");</p>
  </blockquote>
  
  <p>Do I need to add the parameter in MainActivity?</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <p>Some part of code snippet in mainActivity</p>
  
  <pre><code> private void selectItem(int position) {
  
              Fragment fragment = null;
  
              switch (position) {
                  case 0:
                      fragment=new Information();
                      break;
                  case 1:
                      fragment=new Claims();
                      break;
  
                  case 2:
                      fragment=new Project();
  
                  case 3:
                      fragment=new Report();
  
                  case 4:
                      fragment=new ViewView();
  
                  default:
                      break;
              }
  
              if (fragment != null) {
                  FragmentManager fragmentManager = getFragmentManager();
                  fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
  
                  mDrawerList.setItemChecked(position, true);
                  mDrawerList.setSelection(position);
                  setTitle(mNavigationDrawerItemTitles[position]);
                  mDrawerLayout.closeDrawer(mDrawerList);
  
              } else {
                  Log.e("MainActivity", "Error in creating fragment");
              }
  </code></pre>
  
  <p><strong>EDITED</strong></p>
  
  <pre><code> Button btn1 = (Button) findViewById(R.id.button2);
          btn1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View arg0) {
                  AlertDialog.Builder builder = new AlertDialog.Builder(WorkDetailsTable.this);
                  builder.setTitle("Data Saved");
                  builder.setMessage("Are you sure you want to save?");
                  builder.setIcon(android.R.drawable.ic_dialog_alert);
                  builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int ii) {
                 long ab = ts.insertTimeSheet(name, weather, date, status,b,i);
                  Bundle bundle =new Bundle();
                  bundle.putLong("ab",ab);
                  Claims o=new Claims();
                  o.setArguments(bundle);
                  }
  </code></pre>
  
  <p><strong>Claims.java</strong></p>
  
  <pre><code>  Bundle bundle=this.getArguments();
    fk=bundle.getLong("ab");
    button1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(getActivity().getApplicationContext(), fk+"", Toast.LENGTH_LONG).show();
                  AlertDialogRadio(a1);
  
  
              }
          });
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>  private void selectItem(int position) {
  
              Fragment fragment = null;
  
              switch (position) {
                  case 0:
                      fragment=new Information();
                      break;
                  case 1:
                      fragment=new Claims();
                      break;
  
                  case 2:
                      fragment=new Project();
                      break;
  
                  case 3:
                      fragment=new Report();
                      break;
  
                  case 4:
                      fragment=new ViewView();
  
                  default:
                      break;
              }
  
              if (fragment != null) {
                  FragmentManager fragmentManager = getFragmentManager();
                  if(fragment instanceof Claims)
                  {
                      Bundle bundle=new Bundle();
                      bundle.putString("ab","ab");
                      fragment.setArguments(bundle);
                      fragment.setArguments(bundle);
                  }
  
                  fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
  
                  mDrawerList.setItemChecked(position, true);
                  mDrawerList.setSelection(position);
                  setTitle(mNavigationDrawerItemTitles[position]);
                  mDrawerLayout.closeDrawer(mDrawerList);
  
              } else {
                  Log.e("MainActivity", "Error in creating fragment");
              }
          }
      }
  </code></pre>