Giter VIP home page Giter VIP logo

Comments (4)

mxn21 avatar mxn21 commented on July 17, 2024

Can you give me the log for the App crash?thanks

from flowingdrawer.

virajt71 avatar virajt71 commented on July 17, 2024

Here is the code:
`public class MenuListFragment extends Fragment {

ImageView ivMenuUserProfilePhoto;
DrawerLayout mDrawerLayout;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_menu, container,
            false);
    mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    ivMenuUserProfilePhoto = (ImageView) view.findViewById(R.id.ivMenuUserProfilePhoto);
    NavigationView vNavigation = (NavigationView) view.findViewById(R.id.vNavigation);
    vNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            Toast.makeText(getActivity(),menuItem.getTitle(),Toast.LENGTH_SHORT).show();
            int id = menuItem.getItemId();
            Intent i = null;
            if (id == R.id.menu_settings){
                i = new Intent(getActivity().getApplicationContext(), SettingActivity.class);
            }
            startActivity(i);
            mDrawerLayout.closeDrawer(GravityCompat.START);
            return true;
        }
    });
    setupHeader();
    return  view ;
}

private void setupHeader() {
    int avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
    String profilePhoto = getResources().getString(R.string.user_profile_photo);
    Picasso.with(getActivity())
            .load(profilePhoto)
            .placeholder(R.drawable.img_circle_placeholder)
            .resize(avatarSize, avatarSize)
            .centerCrop()
            .transform(new CircleTransformation());
}

}`

log :
04-26 10:13:45.348 16915-16915/com.example.soulreaper.automation E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.closeDrawer(int)' on a null object reference
at com.example.soulreaper.automation.activity.MenuListFragment$1.onNavigationItemSelected(MenuListFragment.java:52)
at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:156)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969)
at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

from flowingdrawer.

mxn21 avatar mxn21 commented on July 17, 2024

you can't get mDrawerLayout object in MenuListFragment, because it's in MainActivity's layout .
You can define a method in MainActivity:
public void closeMenu() {
if (mDrawer.isMenuVisible()) {
mDrawer.closeMenu();
}
}

and in MenuListFragment use : ((MainActivity)getActivity()).closeMenu() ;

from flowingdrawer.

virajt71 avatar virajt71 commented on July 17, 2024

I did try this method but maybe i have put some thing else instead of
"((MainActivity)getActivity()).closeMenu() ;" so, it did not work. Thanks for the solution.

from flowingdrawer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.