android:array index out of bound exception - android

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends Activity {
private DrawerLayout drawerLayout;
private ListView lvSlidingMenu;
private ActionBarDrawerToggle drawerToggle; // Navigation Drawer titles
private CharSequence drawerTitle;
private CharSequence appTitle;
// Sliding Menu items
private String[] titles;
private TypedArray icons;
private ArrayList slidingMenuItems;
private SlidingMenuAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appTitle = drawerTitle = getTitle();
// Load resources
titles = getResources().getStringArray(R.array.nav_drawer_items);
icons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
// Get Sliding Menu ListView istance
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
lvSlidingMenu = (ListView) findViewById(R.id.lv_sliding_menu);
slidingMenuItems = new ArrayList();
// Creating and Adding SlidingMenuItems
slidingMenuItems.add(new SlidingMenuItem(titles[0], icons.getResourceId(0,-1)));
slidingMenuItems.add(new SlidingMenuItem(titles[1], icons.getResourceId(1, -1)));
slidingMenuItems.add(new SlidingMenuItem(titles[2], icons.getResourceId(2, -1)));
slidingMenuItems.add(new SlidingMenuItem(titles[3], icons.getResourceId(3, -1)));
// Recycle the typed array
icons.recycle();
lvSlidingMenu.setOnItemClickListener(new SlideMenuClickListener());
// Assign adapter to listview
adapter = new SlidingMenuAdapter(getApplicationContext(), slidingMenuItems);
lvSlidingMenu.setAdapter(adapter);
// Enable action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer
// Navigation Drawer
, R.string.app_name,
//Navigation Drawer open - description for accessibility
R.string.app_name)
// Navigation Drawer close - description for accessibility
{
public void onDrawerClosed(View view) {
getActionBar().setTitle(appTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(drawerTitle);
invalidateOptionsMenu();
}
}; drawerLayout.setDrawerListener(drawerToggle);
if (savedInstanceState == null) {
// On first time, show Home Fragment
displayView(0);
}
}
/**
* Slide menu item click listener *
*/
private class SlideMenuClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Display appropriate fragment for selected item
displayView(position);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Toggle Navigation Drawer on selecting action bar app icon/title
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
} /* * * Called when invalidateOptionsMenu() is triggered */
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If Navigation Drawer is opened, hide the action items
boolean drawerOpen = drawerLayout.isDrawerOpen(lvSlidingMenu);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Display fragment view for selected Navigation Drawer list item *
*/
private void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new HomeFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.fragment_detail, fragment).commit();
// Update selected item and title, then close the drawer
lvSlidingMenu.setItemChecked(position, true);
lvSlidingMenu.setSelection(position);
setTitle(titles[position]);
drawerLayout.closeDrawer(lvSlidingMenu);
} else {
// Log error
Log.e("MainActivity", "Error in creating fragment");
}
}
#Override
public void setTitle(CharSequence title) {
appTitle = title;
getActionBar().setTitle(appTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during * onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
drawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
drawerToggle.onConfigurationChanged(newConfig);
}
}
This is my MainActivty.java
public class SlidingMenuAdapter extends BaseAdapter {
private Context context;
private ArrayList<SlidingMenuItem> items;
public SlidingMenuAdapter(Context context, ArrayList<SlidingMenuItem> items) {
this.context = context;
this.items = items;
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int index) {
return items.get(index);
}
#Override
public long getItemId(int index) {
return index;
}
#Override
public View getView(int index, View view, ViewGroup arg2) {
if (view == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
view = mInflater.inflate(R.layout.iv_item_sliding_menu, null);
}
ImageView imgIcon = (ImageView) view.findViewById(R.id.img_sliding_menu_item);
TextView txtTitle = (TextView) view.findViewById(R.id.tv_sliding_menu_item);
SlidingMenuItem item = items.get(index);
imgIcon.setImageResource(item.getIcon());
txtTitle.setText(item.getTitle());
return view;
}
}
This is my adapter.java file
public class SlidingMenuItem {
String title;
int icon;
public SlidingMenuItem(String title, int icon) {
this.title = title;
this.icon = icon;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getIcon() {
return icon;
}
public void setIcon(int icon) {
this.icon = icon;
}
}
And this is my menu item
<resources>
<string name="app_name" translatable="false">Fb slid</string>
<string name="hello_world" translatable="false">Hello world!</string>
<string name="action_settings" translatable="false">Settings</string>
<string name="title_activity_main" translatable="false">MainActivity
</string>
<!-- Sliding Menu items -->
<string-array name="nav_drawer_items">
<item >Home</item>
<item >Notifications</item>
<item >Settings</item>
<item >About</item>
</string-array>
<!-- Sliding Menu item icons -->
<array name="nav_drawer_icons">
<item>#drawable/home</item>
<item>#drawable/notifications</item>
<item>#drawable/settings</item>
<item>#drawable/about</item>
</array>
</resources>
And this s my string.xml file
Log cat :
10-03 11:02:06.217 6956-6956/com.example.first.fbslid E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first.fbslid/com.example.first.fbslid.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at com.example.first.fbslid.MainActivity.onCreate(MainActivity.java:49)
at android.app.Activity.performCreate(Activity.java:5207)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
            at android.app.ActivityThread.access$700(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:177)
            at android.app.ActivityThread.main(ActivityThread.java:4947)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
            at dalvik.system.NativeStart.main(Native Method).
I don't know where am getting error as am new to android and am trying to create sliding menu like in facebook . Can someone Please help me to resolve

I think is the
<!-- Sliding Menu items -->
that its empty, and then when you try to read the menu item array it fails
titles = getResources().getStringArray(R.array.nav_drawer_items);

Related

cannot start an activity via an Intent from the nav drawer

I am trying to implement a navigation drawer and use it in multiple activities. But when I try to start another activity (when I click on the item in the navigation drawer), the app crashes and displays a force close message.
Here is my Main activity called Home:
package com.radoslav.socialreminder;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class Home extends AppCompatActivity
implements NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_new);
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
}
#Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();
Intent intent;
if(position == 0)
{
}
else if(position == 1)
{
try {
intent = new Intent(Home.this, MyTasks.class);
startActivity(intent);
}
catch (Exception e)
{
System.out.println("exception occurred: " + e);
}
}
else if(position == 2)
{
intent = new Intent(Home.this, Group_tasks.class);
startActivity(intent);
}
else if(position == 3)
{
intent = new Intent(Home.this, What_do_I_miss.class);
startActivity(intent);
}
else
{
Toast.makeText(this, "An error has occurred!", Toast.LENGTH_LONG).show();
}
}
#Override
public void onBackPressed() {
if (mNavigationDrawerFragment.isDrawerOpen())
mNavigationDrawerFragment.closeDrawer();
else
super.onBackPressed();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.home_new, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my interface:
package com.radoslav.socialreminder;
public interface NavigationDrawerCallbacks {
void onNavigationDrawerItemSelected(int position);
}
NavigationDrawerAdapter:
package com.radoslav.socialreminder;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.ViewHolder> {
private List<NavigationItem> mData;
private NavigationDrawerCallbacks mNavigationDrawerCallbacks;
private View mSelectedView;
private int mSelectedPosition;
public NavigationDrawerAdapter(List<NavigationItem> data) {
mData = data;
}
public NavigationDrawerCallbacks getNavigationDrawerCallbacks() {
return mNavigationDrawerCallbacks;
}
public void setNavigationDrawerCallbacks(NavigationDrawerCallbacks navigationDrawerCallbacks) {
mNavigationDrawerCallbacks = navigationDrawerCallbacks;
}
#Override
public NavigationDrawerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.drawer_row, viewGroup, false);
final ViewHolder viewHolder = new ViewHolder(v);
viewHolder.itemView.setClickable(true);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mSelectedView != null) {
mSelectedView.setSelected(false);
}
mSelectedPosition = viewHolder.getPosition();
v.setSelected(true);
mSelectedView = v;
if (mNavigationDrawerCallbacks != null)
mNavigationDrawerCallbacks.onNavigationDrawerItemSelected(viewHolder.getPosition());
}
}
);
viewHolder.itemView.setBackgroundResource(R.drawable.row_selector);
return viewHolder;
}
#Override
public void onBindViewHolder(NavigationDrawerAdapter.ViewHolder viewHolder, int i) {
viewHolder.textView.setText(mData.get(i).getText());
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(mData.get(i).getDrawable(), null, null, null);
if (mSelectedPosition == i) {
if (mSelectedView != null) {
mSelectedView.setSelected(false);
}
mSelectedPosition = i;
mSelectedView = viewHolder.itemView;
mSelectedView.setSelected(true);
}
}
public void selectPosition(int position) {
mSelectedPosition = position;
notifyItemChanged(position);
}
#Override
public int getItemCount() {
return mData != null ? mData.size() : 0;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView textView;
public ViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.item_name);
}
}
}
And NavigationDrawerFragment:
package com.radoslav.socialreminder;
import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.lang.String;
import java.util.ArrayList;
import java.util.List;
/**
* Fragment used for managing interactions for and presentation of a navigation drawer.
* See the <a href="https://developer.android.com/design/patterns/navigation-drawer.html#Interaction">
* design guidelines</a> for a complete explanation of the behaviors implemented here.
*/
public class NavigationDrawerFragment extends Fragment implements NavigationDrawerCallbacks {
/**
* Remember the position of the selected item.
*/
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
/**
* Per the design guidelines, you should show the drawer on launch until the user manually
* expands it. This shared preference tracks this.
*/
private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
/**
* A pointer to the current callbacks instance (the Activity).
*/
private NavigationDrawerCallbacks mCallbacks;
/**
* Helper component that ties the action bar to the navigation drawer.
*/
private ActionBarDrawerToggle mActionBarDrawerToggle;
private DrawerLayout mDrawerLayout;
private RecyclerView mDrawerList;
private View mFragmentContainerView;
private int mCurrentSelectedPosition = 0;
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
private String item1 = "Home";
private String item2 = "My tasks";
private String item3 = "Group tasks";
private String item4 = "What do I miss?";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println(item1);
// Read in the flag indicating whether or not the user has demonstrated awareness of the
// drawer. See PREF_USER_LEARNED_DRAWER for details.
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
if (savedInstanceState != null) {
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
mFromSavedInstanceState = true;
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_navigation_drawer_new, container, false);
mDrawerList = (RecyclerView) view.findViewById(R.id.drawerList);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mDrawerList.setLayoutManager(layoutManager);
mDrawerList.setHasFixedSize(true);
final List<NavigationItem> navigationItems = getMenu();
NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(navigationItems);
adapter.setNavigationDrawerCallbacks(this);
mDrawerList.setAdapter(adapter);
selectItem(mCurrentSelectedPosition);
return view;
}
public boolean isDrawerOpen() {
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
}
public ActionBarDrawerToggle getActionBarDrawerToggle() {
return mActionBarDrawerToggle;
}
public DrawerLayout getDrawerLayout() {
return mDrawerLayout;
}
#Override
public void onNavigationDrawerItemSelected(int position) {
selectItem(position);
}
public List<NavigationItem> getMenu() {
List<NavigationItem> items = new ArrayList<NavigationItem>();
items.add(new NavigationItem(item1, getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem(item2, getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem(item3, getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem(item4, getResources().getDrawable(R.drawable.ic_menu_check)));
return items;
}
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* #param fragmentId The android:id of this fragment in its activity's layout.
* #param drawerLayout The DrawerLayout containing this fragment's UI.
* #param toolbar The Toolbar of the activity.
*/
public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.myPrimaryDarkColor));
mActionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) return;
getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) return;
if (!mUserLearnedDrawer) {
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
};
// If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
#Override
public void run() {
mActionBarDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
}
private void selectItem(int position) {
mCurrentSelectedPosition = position;
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
if (mCallbacks != null) {
mCallbacks.onNavigationDrawerItemSelected(position);
}
((NavigationDrawerAdapter) mDrawerList.getAdapter()).selectPosition(position);
}
public void openDrawer() {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
public void closeDrawer() {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallbacks = (NavigationDrawerCallbacks) activity;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
}
}
#Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Forward the new configuration the drawer toggle component.
mActionBarDrawerToggle.onConfigurationChanged(newConfig);
}
}
This is what the logcat spits out when the app crashes:
08-07 14:42:16.765 941-941/com.radoslav.socialreminder I/System.out﹕ Home
08-07 14:42:16.775 941-941/com.radoslav.socialreminder D/AndroidRuntime﹕ Shutting down VM
08-07 14:42:16.775 941-941/com.radoslav.socialreminder W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41b30700)
08-07 14:42:16.790 941-941/com.radoslav.socialreminder E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.radoslav.socialreminder/com.radoslav.socialreminder.MyTasks}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
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:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.internal.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:94)
at android.support.v7.internal.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:87)
at android.support.v7.internal.app.ToolbarActionBar.<init>(ToolbarActionBar.java:79)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:198)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:96)
at com.radoslav.socialreminder.MyTasks.onCreate(MyTasks.java:26)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            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:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)
08-07 14:42:16.795 2430-2780/? I/ActivityManager﹕ Notify an ApplicationCrash
Thank you, here is the MyTasks.class but I have commented out most of it
package com.radoslav.socialreminder;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MyTasks extends ActionBarActivity{
// implements NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_tasks);
/* mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);*/
}
/* #Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();
}
#Override
public void onBackPressed() {
if (mNavigationDrawerFragment.isDrawerOpen())
mNavigationDrawerFragment.closeDrawer();
else
super.onBackPressed();
}
*/
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.home_new, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

how to use collapse in navigation drawer

navigation drawer list class
package com.example.navigation;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class NavDrawerListAdapter extends BaseAdapter {
private Context context;
private ArrayList<NavDrawerItem> navDrawerItems;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems){
this.context = context;
this.navDrawerItems = navDrawerItems;
}
#Override
public int getCount() {
return navDrawerItems.size();
}
#Override
public Object getItem(int position) {
return navDrawerItems.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
imgIcon.setImageResource(navDrawerItems.get(position).getIcon());
txtTitle.setText(navDrawerItems.get(position).getTitle());
return convertView;
}
}
this is my main activity
package com.example.navigation;
import java.util.ArrayList;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
public class MainActivity extends ActionBarActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
protected RelativeLayout _completeLayout, _activityLayout;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// if (savedInstanceState == null) {
// // on first time display view for first nav item
// // displayView(0);
// }
}
public void set(String[] navMenuTitles, TypedArray navMenuIcons) {
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items
if (navMenuIcons == null) {
for (int i = 0; i < navMenuTitles.length; i++) {
navDrawerItems.add(new NavDrawerItem(navMenuTitles[i]));
}
} else {
for (int i = 0; i < navMenuTitles.length; i++) {
navDrawerItems.add(new NavDrawerItem(navMenuTitles[i],
navMenuIcons.getResourceId(i, -1)));
}
}
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// getSupportActionBar().setIcon(R.drawable.ic_drawer);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_launcher, // nav menu toggle icon
R.string.app_name, // nav drawer open - description for
// accessibility
R.string.app_name // nav drawer close - description for
// accessibility
) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
}
return super.onOptionsItemSelected(item);
}
/***
* Called when invalidateOptionsMenu() is triggered
*/
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
// boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
// menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
switch (position) {
case 0:
Intent intent = new Intent(this, FirstActivity.class);
startActivity(intent);
finish();// finishes the current activity
break;
case 1:
Intent intent1 = new Intent(this, SecondActivity.class);
startActivity(intent1);
finish();// finishes the current activity
break;
// case 2:
// Intent intent2 = new Intent(this, third.class);
// startActivity(intent2);
// finish();
// break;
// case 3:
// Intent intent3 = new Intent(this, fourth.class);
// startActivity(intent3);
// finish();
// break;
// case 4:
// Intent intent4 = new Intent(this, fifth.class);
// startActivity(intent4);
// finish();
// break;
// case 5:
// Intent intent5 = new Intent(this, sixth.class);
// startActivity(intent5);
// finish();
// break;
default:
break;
}
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
mDrawerLayout.closeDrawer(mDrawerList);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
drawer item
package com.example.navigation;
public class NavDrawerItem {
private String title;
private int icon;
public NavDrawerItem() {
}
public NavDrawerItem(String title, int icon) {
this.title = title;
this.icon = icon;
}
public NavDrawerItem(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public int getIcon() {
return this.icon;
}
public void setTitle(String title) {
this.title = title;
}
public void setIcon(int icon) {
this.icon = icon;
}
}
I created a navigation drawer menu item but now i want to create sub menu item in navigation drawer menu item. So how can i create this please suggest me thanks in advance
Here is my navigation Drawer menu item code which we r created in String.xml
<string-array name="nav_drawer_items">
<item>First</item>
<item>Second</item>
<item>Third</item>
<item>Fourth</item>
<item>Fifth</item>
<item>Sixth</item>
</string-array>
Check the following link..
that helps you to create expandable listview in navigation drawer.
android-custom-navigation-drawer
You should check Andtroid Hive Example also.
Some more links that may be helpful to you.
Navigation drawer with Expandable list view - 1
Navigation drawer with Expandable list view - 2
You need customize your navigation drawer menu. Actually looks like use a simple ListView, if you need subsecction, you should use ExpandableListView. Something like this:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
If show your code or how you create the navigation drawer, we can help you with replace your actual menu with the custom menu.

Attempt to invoke virtual method on a null object reference - drawer layout

I'm creating a parent activity that extends ActionBarActivity which all of my activities will extend (so I only have to do drawer setup once).
I keep getting a null pointer exception on the setAdapter method of my drawer's list and can't figure out why.
Here's the parent activity:
(The crash log shows it's being cause in this activity, I put a comment at the end of that line)
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.makeramen.RoundedImageView;
import com.makeramen.RoundedTransformationBuilder;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Transformation;
public class MainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
// Action bar
private ActionBar actionBar;
private Toolbar toolbar;
// Navigation Drawer
private ActionBarDrawerToggle drawerToggle;
private DrawerLayout drawerLayout;
private ListView drawerList;
private RelativeLayout drawerHeader;
private ImageView drawerHeaderBG;
private RoundedImageView userImage;
private TextView userName;
public void setupActivity() {
setMyActionBar();
createDrawer();
}
public void setMyActionBar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(getString(R.string.app_name));
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(getSupportFragmentManager().getBackStackEntryCount() > 0);
}
public void createDrawer() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.post(new Runnable() {
#Override
public void run() {
drawerList = (ListView) drawerLayout.findViewById(R.id.left_drawer);
drawerList.setMinimumWidth(((View) findViewById(R.id.baseLayoutRootParent)).getWidth() - actionBar.getHeight());
if (drawerList.getHeaderViewsCount() == 0)
drawerList.addHeaderView(drawerHeader);
drawerList.setAdapter(new DrawerAdapter(MainActivity.this)); // crash happens here
drawerList.setOnItemClickListener(MainActivity.this);
drawerToggle = new ActionBarDrawerToggle(
MainActivity.this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_action_navigation_menu, /* nav drawer icon to replace 'Up' caret */
R.string.open_drawer, /* "open drawer" description */
R.string.close_drawer /* "close drawer" description */
) {
/**
* Called when a drawer has settled in a completely closed state.
*/
public void onDrawerClosed(View view) {
actionBar.setTitle(getString(R.string.app_name));
}
/**
* Called when a drawer has settled in a completely open state.
*/
public void onDrawerOpened(View drawerView) {
actionBar.setTitle(getString(R.string.app_name));
}
};
// Set the drawer toggle as the DrawerListener
drawerLayout.setDrawerListener(drawerToggle);
drawerToggle.syncState();
}
});
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// drawer list item click events
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
#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_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.action_settings:
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's the activity that extends the previous one:
public class HomeActivity extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
setupActivity();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainer, MainFragment.newInstance()).commit();
}
}
here's the adapter for the drawer list:
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class DrawerAdapter extends BaseAdapter {
private Context context;
private String[] items;
public DrawerAdapter(Context context) {
this.context = context;
items = context.getResources().getStringArray(R.array.drawer_array);
}
#Override
public int getCount() {
return items.length;
}
#Override
public String getItem(int position) {
return items[position];
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.drawer_list_item, parent, false);
holder.image = (ImageView) convertView.findViewById(R.id.drawerItemImage);
holder.text = (TextView) convertView.findViewById(R.id.drawerItemText);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.image.setImageResource(getIcon(position));
holder.text.setText(getItem(position));
return convertView;
}
private int getIcon(int position) {
switch (position) {
case 0:
return R.drawable.ic_action_home_blue;
case 1:
return R.drawable.ic_action_heart_blue;
case 2:
return R.drawable.ic_action_search_blue;
case 3:
return R.drawable.ic_action_map_blue;
case 4:
return R.drawable.ic_action_wheel_blue;
case 5:
return R.drawable.ic_action_calendar_blue;
case 6:
return R.drawable.ic_action_parameters_blue;
}
return 0;
}
class ViewHolder {
private ImageView image;
private TextView text;
}
}
and just in case you need it, here's the layout file:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color">
<!-- The main content view -->
<LinearLayout
android:id="#+id/baseLayoutRootParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:bar="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:gravity="end|center_vertical"
android:paddingEnd="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingStart="#dimen/activity_horizontal_margin"
bar:theme="#style/ThemeOverlay.AppCompat.ActionBar" />
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The drawer content view -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/background"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
and FINALLY, here's the error log:
02-27 13:05:55.205 11723-11723/com.example.myApp.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.myApp.app, PID: 11723
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at android.widget.ListView.clearRecycledState(ListView.java:539)
at android.widget.ListView.resetList(ListView.java:525)
at android.widget.ListView.setAdapter(ListView.java:469)
at com.example.myApp.app.MainActivity$1.run(MainActivity.java:92)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
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:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Thanks in advance!
EDIT
I've tried calling setupActivity() from onCreate, onPostCreate, and onResume and get the same error in all 3
So, I had this weird error as well, yet my error log didn't point to any line of code in my app, so it was a guessing game as to what was the problem.
It was:
listView.scrollToPosition(0);
Cursor results = performQuery();
if(results != null){
adapter.changeCursor(results);
}
My crash came from when I had no results, so I finally decided to use an empty view.
Cursor results = performQuery();
if(results != null && results.getCount() > 0){
listView.setVisibility(View.VISIBLE);
emptyView.setVisibility(View.GONE);
adapter.changeCursor(results);
listView.scrollToPosition(0);
}
else{
emptyView.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
}
This fixed my crash. As a note, I'm using the new RecyclerView.

FATAL EXCEPTION: main Process: java.lang.IllegalStateException: Could not execute method of the activity

Been trying to get my IntroActivity.java to enter my FmMenu.java (which is a fragment) and I am getting the following error:
02-26 02:10:58.197 25189-25189/com.wlodsgn.bunbunup E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.wlodsgn.bunbunup, PID: 25189
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
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:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            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:5221)
            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:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wlodsgn.bunbunup/com.wlodsgn.bunbunup.FmMenu}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1761)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
at android.app.Activity.startActivityForResult(Activity.java:3736)
at android.app.Activity.startActivityForResult(Activity.java:3697)
at android.app.Activity.startActivity(Activity.java:4007)
at android.app.Activity.startActivity(Activity.java:3975)
at com.wlodsgn.bunbunup.IntroActivity.startMenuActivity(IntroActivity.java:51)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4002)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            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:5221)
            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:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Here is my IntroActivity.java (Where my app start and should enter FmMenu with a button click)
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
/**
* Created by WiLo on 2/13/2015.
*/
public class IntroActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
/*getActionBar().hide();*/
setContentView(R.layout.activity_intro);
Log.i("BunBunUp", "MainActivity Created");
}
/**#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_intro, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}**/
public void startMenuActivity(View v){
Intent intent = new Intent(IntroActivity.this, FmMenu.class);
startActivity(intent);
}
protected void onResume(){
super.onResume();
Log.i("BunBunUp", "IntroActivity Resumed");
}
protected void onPause(){
super.onPause();
Log.i("BunBunUp", "IntroActivity Paused");
}
protected void onStop(){
super.onStop();
Log.i("BunBunUp", "IntroActivity Stopped");
}
}
FmMenu.java
import java.util.ArrayList;
import java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by WiLo on 2/13/2015.
*/
public class FmMenu extends Fragment {
String[] categoria = {
"Jeans"
};
int[] imagenes = {
R.drawable.veroxjeans1,
R.drawable.veroxjeans2,
R.drawable.veroxjeans3,
R.drawable.veroxjeans4,
R.drawable.veroxjeans5,
R.drawable.veroxjeans6,
R.drawable.veroxjeans7
};
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.lay_menufragment, container, false);
//lista
ListView lista = (ListView) rootView.findViewById(R.id.listView1);
ArrayAdapter adapter = new ArrayAdapter(this.getActivity(), android.R.layout.simple_list_item_1, categoria);
lista.setAdapter(adapter);
//galeria de imagenes
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[0]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[1]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[2]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[3]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[4]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[5]));
mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[6]));
mViewPager.setAdapter(mSectionsPagerAdapter);
return rootView;
}
/**#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_menufragment);
}**/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
List<Fragment> fragmentos;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
fragmentos = new ArrayList<Fragment>();
}
public void addfragments(Fragment xfragment){
fragmentos.add(xfragment);
}
#Override
public Fragment getItem(int position) {
return fragmentos.get(position);
}
#Override
public int getCount() {
return fragmentos.size();
}
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_IMAGE = "imagen";
private int imagen;
public static PlaceholderFragment newInstance(int imagen) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_IMAGE, imagen);
fragment.setArguments(args);
fragment.setRetainInstance(true);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getArguments() != null) {
imagen = getArguments().getInt(ARG_IMAGE);
}
}
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_menu, container, false);
ImageView imagenView = (ImageView) rootView.findViewById(R.id.imageView1);
imagenView.setImageResource(imagen);
return rootView;
}
}
}
MenuActivity.java (which contains navigation drawer and search box)
import java.util.ArrayList;
import java.util.List;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.MenuItemCompat.OnActionExpandListener;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SearchView.OnQueryTextListener;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
/**
* Created by WiLo on 2/13/2015.
*/
public class MenuActivity extends ActionBarActivity implements OnQueryTextListener, OnActionExpandListener{
/*private TextView texto;*/
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
/*texto = (TextView) findViewById(R.id.texto);*/
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
navDrawerItems = new ArrayList<NavDrawerItem>();
// agregar un nuevo item al menu deslizante
// Menu
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// Contacto
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
// Catologo
//navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1), true, "Estrenos"));
// old Contacto (Pedidos)
//navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Recycle the typed array
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}
#Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
Toast.makeText(getApplicationContext(), "Abriendo Busqueda", Toast.LENGTH_SHORT).show();
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
Toast.makeText(getApplicationContext(), "Cerrando Busqueda", Toast.LENGTH_SHORT).show();
return true;
}
#Override
public boolean onQueryTextSubmit(String s) {
/*texto.setText("Buscando...\n\n" + s);*/
return false;
}
#Override
public boolean onQueryTextChange(String s) {
/*texto.setText(" \n\n" + s);*/
return false;
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.menu3_buscar);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(this);
MenuItemCompat.setOnActionExpandListener(searchItem, this);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new FmMenu();
break;
case 1:
fragment = new FmContacto();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
// error in creating fragment
Log.e("BunBunUp", "MenuActivity - Error cuando se creo el fragment");
}
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggle
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
Any suggestion would be appreciated
You opening Fragment instead of activity..
Your Code :
public void startMenuActivity(View v){
Intent intent = new Intent(IntroActivity.this, FmMenu.class);
startActivity(intent);
}
Please change FmMenu.java to activity instead of fragment

Cannot resolve symbol in main activity java class

I cannot find out what the problem is here! I am following this tutorial for building a navigation drawer with fragments and I cannot find a way to fix the "cannot resolve symbol error". The error is on "drawer_nav_item". I have looked for unused classes and other times that it is used and cannot find it! Please Help! I can provide more code upon request
This is my activity_main.xml
package com.nhscoding.safe2tell;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
import com.nhscoding.safe2tell.AboutClass;
import com.nhscoding.safe2tell.FragmentNavigationDrawer;
import com.nhscoding.safe2tell.LearnClass;
import com.nhscoding.safe2tell.R;
import com.nhscoding.safe2tell.SettingsClass;
import com.nhscoding.safe2tell.StoriesClass;
import com.nhscoding.safe2tell.SubmitClass;
public class MainActivity extends FragmentActivity {
private FragmentNavigationDrawer dlDrawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find our drawer view
dlDrawer = (FragmentNavigationDrawer) findViewById(R.id.drawer_layout);
// Setup drawer view
dlDrawer.setupDrawerConfiguration((ListView) findViewById(R.id.lvDrawer),
R.layout.drawer_nav_item, R.id.flContent);
// Add nav items
dlDrawer.addNavItem("Submit", "Submit Class", SubmitClass.class);
dlDrawer.addNavItem("Second", "Second Fragment", StoriesClass.class);
dlDrawer.addNavItem("Third", "Third Fragment", LearnClass.class);
dlDrawer.addNavItem("Fouth", "Fourth Fragment", AboutClass.class);
dlDrawer.addNavItem("Fifth", "Fifth Fragment", SettingsClass.class);
// Select default
if (savedInstanceState == null) {
dlDrawer.selectDrawerItem(0);
}
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content
if (dlDrawer.isDrawerOpen()) {
// Uncomment to hide menu items
// menu.findItem(R.id.mi_test).setVisible(false);
}
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// Uncomment to inflate menu items to Action Bar
// inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (dlDrawer.getDrawerToggle().onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
dlDrawer.getDrawerToggle().syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggles
dlDrawer.getDrawerToggle().onConfigurationChanged(newConfig);
}
}
Here is my Navigation Drawer Class
package com.nhscoding.safe2tell;
import java.util.ArrayList;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.nhscoding.safe2tell.R;
public class FragmentNavigationDrawer extends DrawerLayout {
private ActionBarDrawerToggle drawerToggle;
private ListView lvDrawer;
private ArrayAdapter<String> drawerAdapter;
private ArrayList<FragmentNavItem> drawerNavItems;
private int drawerContainerRes;
public FragmentNavigationDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FragmentNavigationDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FragmentNavigationDrawer(Context context) {
super(context);
}
// setupDrawerConfiguration((ListView) findViewById(R.id.lvDrawer), R.layout.drawer_list_item, R.id.flContent);
public void setupDrawerConfiguration(ListView drawerListView, int drawerItemRes, int drawerContainerRes) {
// Setup navigation items array
drawerNavItems = new ArrayList<FragmentNavigationDrawer.FragmentNavItem>();
// Set the adapter for the list view
drawerAdapter = new ArrayAdapter<String>(getActivity(), drawerItemRes,
new ArrayList<String>());
this.drawerContainerRes = drawerContainerRes;
// Setup drawer list view and related adapter
lvDrawer = drawerListView;
lvDrawer.setAdapter(drawerAdapter);
// Setup item listener
lvDrawer.setOnItemClickListener(new FragmentDrawerItemListener());
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
drawerToggle = setupDrawerToggle();
setDrawerListener(drawerToggle);
// set a custom shadow that overlays the main content when the drawer
setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// Setup action buttons
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
// addNavItem("First", "First Fragment", FirstFragment.class)
public void addNavItem(String navTitle, String windowTitle, Class<? extends Fragment> fragmentClass) {
drawerAdapter.add(navTitle);
drawerNavItems.add(new FragmentNavItem(windowTitle, fragmentClass));
}
/** Swaps fragments in the main content view */
public void selectDrawerItem(int position) {
// Create a new fragment and specify the planet to show based on
// position
FragmentNavItem navItem = drawerNavItems.get(position);
Fragment fragment = null;
try {
fragment = navItem.getFragmentClass().newInstance();
Bundle args = navItem.getFragmentArgs();
if (args != null) {
fragment.setArguments(args);
}
} catch (Exception e) {
e.printStackTrace();
}
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().replace(drawerContainerRes, fragment).commit();
// Highlight the selected item, update the title, and close the drawer
lvDrawer.setItemChecked(position, true);
setTitle(navItem.getTitle());
closeDrawer(lvDrawer);
}
public ActionBarDrawerToggle getDrawerToggle() {
return drawerToggle;
}
private FragmentActivity getActivity() {
return (FragmentActivity) getContext();
}
private ActionBar getSupportActionBar() {
return ((ActionBarActivity) getActivity()).getSupportActionBar();
}
private void setTitle(CharSequence title) {
getSupportActionBar().setTitle(title);
}
private class FragmentDrawerItemListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectDrawerItem(position);
}
}
private class FragmentNavItem {
private Class<? extends Fragment> fragmentClass;
private String title;
private Bundle fragmentArgs;
public FragmentNavItem(String title, Class<? extends Fragment> fragmentClass) {
this(title, fragmentClass, null);
}
public FragmentNavItem(String title, Class<? extends Fragment> fragmentClass, Bundle args) {
this.fragmentClass = fragmentClass;
this.fragmentArgs = args;
this.title = title;
}
public Class<? extends Fragment> getFragmentClass() {
return fragmentClass;
}
public String getTitle() {
return title;
}
public Bundle getFragmentArgs() {
return fragmentArgs;
}
}
private ActionBarDrawerToggle setupDrawerToggle() {
return new ActionBarDrawerToggle(getActivity(), /* host Activity */
this, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
// setTitle(getCurrentTitle());
// call onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
// setTitle("Navigate");
// call onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
};
}
public boolean isDrawerOpen() {
return isDrawerOpen(lvDrawer);
}
}
The issue is that you have not defined your layout: drawer_nav_item
#Override
public void onCreate(Bundle sIS){
super(sIS);
setContentView(R.layout.activity_main);
// Find our drawer view
dlDrawer = (FragmentNavigationDrawer) findViewById(R.id.drawer_layout);
// Setup drawer view
dlDrawer.setupDrawerConfiguration((ListView)findViewById(R.id.lvDrawer),
R.layout.drawer_nav_item, /* <- this layout has not been defined
in your layouts folder */
R.id.flContent);
...
}

Categories

Resources