• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Menu not visible in android device

Hi,
I have made a simple menu in android studio 3.2.1. The menu items shows ok in design view. However when i connect it to genymotion or youwave emulator it is invisible and when i click on the 3 dots in the action bar it says that unfortunately the app has stopped

The activity_main.xml file reads

Code:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


</LinearLayout>

The categegory.xml file reads as

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:tools="http://schemas.android.com/tools"
<item
android:visible="true"
android:id="@+id/item1"
android:icon="@drawable/ic_launcher_foreground"
android:title="Item_Sales 1"

>

</item>
<item
android:visible="true"
android:id="@+id/item2"
android:icon="@drawable/ic_launcher_background"
android:title="Item_Sales 2"

>

</item>
<item
android:visible="true"
android:id="@+id/item3"
android:icon="@drawable/ic_launcher_foreground"
android:title="Item_Sales 3">

</item>
</menu>


and the MainActivity.java file reads as

package sun.rudraapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.zip.Inflater;

import static sun.rudraapp.R.menu.categegorymenuxml;

public class MainActivity extends AppCompatActivity {

/**
* Initialize the contents of the Activity's standard options menu. You
* should place your menu items in to <var>menu</var>.
*
* <p>This is only called once, the first time the options menu is
* displayed. To update the menu every time it is displayed, see
* {@link #onPrepareOptionsMenu}.
*
* <p>The default implementation populates the menu with standard system
* menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that
* they will be correctly ordered with application-defined menu items.
* Deriving classes should always call through to the base implementation.
*
* <p>You can safely hold on to <var>menu</var> (and any items created
* from it), making modifications to it as desired, until the next
* time onCreateOptionsMenu() is called.
*
* <p>When you add items to the menu, you can implement the Activity's
* {@link #onOptionsItemSelected} method to handle them there.
*
* @param menu The options menu in which you place your items.
* @return You must return true for the menu to be displayed;
* if you return false it will not be shown.
* @see #onPrepareOptionsMenu
* @see #onOptionsItemSelected
*/
@override
public boolean onCreateOptionsMenu(Menu menu) {


super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.categegorymenuxml, menu);

return true;
}

/**
* This hook is called whenever an item in your options menu is selected.
* The default implementation simply returns false to have the normal
* processing happen (calling the item's Runnable or sending a message to
* its Handler as appropriate). You can use this method for any items
* for which you would like to do processing without those other
* facilities.
*
* <p>Derived classes should call through to the base class for it to
* perform the default menu handling.</p>
*
* @param item The menu item that was selected.
* @return boolean Return false to allow normal menu processing to
* proceed, true to consume it here.
* @see #onCreateOptionsMenu
*/
@override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.item1:
Toast.makeText(this, "Item 1 selected", Toast.LENGTH_LONG).show();

/* case R.id.subitem1:
Toast.makeText(this, "Sub Item 1 selected", Toast.LENGTH_SHORT).show();*/
Default:
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* setSupportActionBar(Toolbar);*/
/*android.support.v7.widget.Toolbar toolbar=findViewById ( R.id.toolbar );*/
/*setSupportActionBar ( toolbar );*/




}
}


and the androidmanifest.xml file reads as

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sun.rudraapp"
>
<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:roundIcon="@Mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@Style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>

Please help

regards

Sanjish
 
Back
Top Bottom