Я использую макет значка в одном пункте менюNullPointerException после replaceing ActionBar с панелью инструментами
здесь некоторый MenuItems
<item
android:id="@+id/action_rdvmed"
android:title="@string/rdv"
android:icon="@drawable/ic_action_action_event"
android:showAsAction="always" />
<item
android:id="@+id/action_msg"
android:title="@string/msg"
android:actionLayout="@layout/badge_layout" <!--this one causes the problem-->
android:showAsAction="always" />
<item
android:id="@+id/action_actualiser"
android:title="@string/actualiser"
android:icon="@drawable/ic_action_refresh"
android:showAsAction="always" />
я получаю исключение нулевого указателя в моем onCreateOptionMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity_med, menu);
this.MenuMed = menu;
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.action_msg).getActionView();
mCounter = (TextView) badgeLayout.findViewById(R.id.hotlist_hot); //the error in this line
imgMessage = (ImageView) badgeLayout.findViewById(R.id.hotlist_bell);
badgeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listMessages.clear();
msg();
}
});
return true;
}
и вот часть muy onCreate methode whare Я использую панель инструментов
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_med);
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
заранее.
Стек след поможет. –
извините, я не сказал, потому что я не думаю, что это помогает взглянуть на принятый ответ –