Comments (4)
Can you give me the log for the App crash?thanks
from flowingdrawer.
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.
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.
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)
- Show/Hide via code HOT 1
- What kind of methods to use?
- The RTL HOT 2
- How to add items in FlowingDrawer dynamically?
- issue when changing locale HOT 1
- Android P devices HOT 6
- java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed HOT 5
- 侧滑阴影
- Failed to run on Android P HOT 1
- code is clean but app crash when running HOT 1
- java.lang.OutOfMemoryError: com.mxn.soul.flowingdrawer_core.BuildLayerFrameLayout.dispatchDraw
- App crash HOT 3
- header divider not showing on right most part, on flowing view
- header divider not showing on right most part, on flowing view HOT 1
- Invalid Region.Op - only INTERSECT and DIFFERENCE HOT 2
- how use custom attributes, edMenuBackground?
- This should be in MIT Licensed in Anroid
- FlowinMenuLayout overlaped with NavigationBar
- Swipe drawer
- FlowingDrawer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flowingdrawer.