title: error:-notication badge on action bar is not showing
body: <p>I am new android.I want to develop an android app in which there is a notification badge on action bar.But the application is not starting.In my activity there is a list which is fetching from server and a dialog on click of list item. There is a null point exception at starting of application.Please guide to solve this error.I am referring this link for making notification badge:- <a href="https://stackoverflow.com/questions/43194243/notification-badge-on-action-item-android">Notification Badge On Action Item Android</a></p>
  
  <p>error:-</p>
  
  <pre><code>Process: com.example.chaitanya.yoga, PID: 4497
                java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
                    at com.example.chaitanya.yoga.record.onCreateOptionsMenu(record.java:201)
                    at android.app.Activity.onCreatePanelMenu(Activity.java:2869)
                    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:548)
                    at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:917)
                    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:258)
                    at android.os.Handler.handleCallback(Handler.java:739)
                    at android.os.Handler.dispatchMessage(Handler.java:95)
                    at android.os.Looper.loop(Looper.java:135)
                    at android.app.ActivityThread.main(ActivityThread.java:5237)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
  </code></pre>
  
  <p>record.class</p>
  
  <pre><code>public class record extends Activity {
  .....
  ArrayList&lt;String&gt; asd;
  private ListView listView;
  String info[];
  String info1[];
  String info2[];
  String info3[];
  String info4[];
  String info5[];
  static int abc;
  int counter = 1;
  TextView textCartItemCount;
  int mCartItemCount = 10;
  
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.record);
  
      asd = new ArrayList&lt;String&gt;();
      new gro().execute();
      SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
      idName = prefs.getInt("idName", 0); 
      Intent intent = new Intent(record.this,
              BackgroundService.class);
      intent.putExtra("counter", counter++);
      startService(intent);
  }
  
  
  class gro extends AsyncTask&lt;String, String, String&gt; {
      protected void onPreExecute() {
          super.onPreExecute();
          ...
      }
  
      protected String doInBackground(String... args) {
          .....
              }
          } catch (JSONException e) {
  
          }
          return null;
  
      }
  
      protected void onPostExecute(String file_url) {
          pDialog.dismiss();
  
          class ViewDialog {
  
              public void showDialog(Activity activity, int pos) {
                  final Dialog dialog = new Dialog(activity);
                  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  dialog.setCancelable(false);
                  dialog.setContentView(R.layout.dialog);
                  TextView text = (TextView) dialog.findViewById(R.id.nm1);
                  TextView text1 = (TextView) dialog.findViewById(R.id.rolln);
                  TextView text2 = (TextView) dialog.findViewById(R.id.bran);
                  TextView text3 = (TextView) dialog.findViewById(R.id.mobi);
                  TextView text4 = (TextView) dialog.findViewById(R.id.emai);
                  TextView text5 = (TextView) dialog.findViewById(R.id.dobb);
                  text.setText(info[pos]);
                  text1.setText("RollNo: " + info1[asd.size() - pos - 1]);
                  text2.setText("Branch: " + info2[asd.size() - pos - 1]);
                  text3.setText("MobileNo: " + info3[asd.size() - pos - 1]);
                  text4.setText("EmailId: " + info4[asd.size() - pos - 1]);
                  text5.setText("DateOfBirth: " + info5[asd.size() - pos - 1]);
  
  
                  Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
                  dialogButton.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          dialog.dismiss();
                      }
                  });
  
                  dialog.show();
  
              }
          }
  
  
          ......
  
          Collections.reverse(Arrays.asList(info));
          customList = new CustomList(record.this, info);
          listView = (ListView) findViewById(R.id.listView);
          listView.setAdapter(customList);
          listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  
              @Override
              public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1,
                                             int position, long arg3) {
                  // TODO Auto-generated method stub
                  ViewDialog alert = new ViewDialog();
                  alert.showDialog(record.this, position);
                  return false;
              }
          });
  
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_main, menu);
  
      final MenuItem menuItem = menu.findItem(R.id.action_cart);
  
      View actionView = MenuItemCompat.getActionView(menuItem);
      textCartItemCount = (TextView) actionView.findViewById(R.id.cart_badge);
      setupBadge();
  
      actionView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              onOptionsItemSelected(menuItem);
          }
      });
  
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  
      switch (item.getItemId()) {
  
          case R.id.action_cart: {
              Toast.makeText(this, "item clickeddddd",
                      Toast.LENGTH_LONG).show();
              textCartItemCount.setVisibility(View.GONE);
              return true;
          }
      }
      return super.onOptionsItemSelected(item);
  }
  
  private void setupBadge() {
  
      if (textCartItemCount != null) {
          if (mCartItemCount == 0) {
              if (textCartItemCount.getVisibility() != View.GONE) {
                  textCartItemCount.setVisibility(View.GONE);
              }
          } else {
              textCartItemCount.setText(String.valueOf(Math.min(mCartItemCount, 99)));
              if (textCartItemCount.getVisibility() != View.VISIBLE) {
                  textCartItemCount.setVisibility(View.VISIBLE);
              }
          }
      }
  
  }
  }
  </code></pre>
  
  <p>manifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.chaitanya.yoga" &gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
       &gt;
      &lt;activity android:name=".record" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
       &lt;service
          android:name=".BackgroundService"
          android:enabled="true"&gt;
      &lt;/service&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>menu_main.xml</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
     &lt;menu 
      xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto" &gt;
      &lt;item
          android:id="@+id/action_cart"
          android:icon="@mipmap/ic_launcher"
          android:title="Cart"
          app:actionLayout="@layout/custom_action_item_layout"
          app:showAsAction="always"/&gt;
     &lt;/menu&gt;
  </code></pre>
  
  <p>badge_background.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"    
   android:shape="oval"&gt;
  
  &lt;solid android:color="@android:color/holo_red_dark"/&gt;
  &lt;stroke android:color="@android:color/white" android:width="1dp"/&gt;
  
  &lt;/shape&gt;
  </code></pre>
  
  <p>record.xml</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;RelativeLayout    
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin"
      tools:context="com.example.chaitanya.yoga.record"&gt;
  
  &lt;ListView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/listView" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>custom_action_item_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
  style="?attr/actionButtonStyle"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:clipToPadding="false"
  android:focusable="true"&gt;
  
  &lt;ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:src="@mipmap/ic_launcher"/&gt;
  
  &lt;TextView
      android:id="@+id/cart_badge"
      android:layout_width="20dp"
      android:layout_height="20dp"
      android:layout_gravity="right|end|top"
      android:layout_marginEnd="-5dp"
      android:layout_marginRight="-5dp"
      android:layout_marginTop="3dp"
      android:background="@drawable/badge_background"
      android:gravity="center"
      android:padding="3dp"
      android:textColor="@android:color/white"
      android:text="0"
      android:textSize="10sp"/&gt;
  </code></pre>
  
  <p></p>