Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views.find() not working properly #1

Closed
zcelaloglu opened this issue Nov 7, 2014 · 4 comments
Closed

Views.find() not working properly #1

zcelaloglu opened this issue Nov 7, 2014 · 4 comments

Comments

@zcelaloglu
Copy link

Hi Alex,

your findViewById implemantation is different so when I try to initialize an object I'm always getting Null Pointer Exception.I always changed from View.fınd(...) to findViewById(....)

I also added your compile 'com.alexvasilkov:android-commons:1.2.3' library as an dependency into build.gradle

@alexvasilkov
Copy link
Owner

Views.find(...) implementation is very straightforward:

public static <T extends View> T find(View parent, int viewId) {
    return (T) parent.findViewById(viewId);
}

public static <T extends View> T find(Activity activity, int viewId) {
    return (T) activity.findViewById(viewId);
}

So if you have NullPointerException there it means you passing null as first argument.

@zcelaloglu
Copy link
Author

Actually I changed your UnFoldableDetailsActivity ->UnFoldableDetailsFragment

so "this" keyword is not valid on Activity so I changed it to getActivity() when I'm defining mDetailsLayout = Views.find(getActivity(), R.id.details_layout); but I'm also getting NPE error in here.

I think View.find() method should be override on Fragment

@alexvasilkov
Copy link
Owner

Fragment.getActivity() will return null if fragment is not attached to activity. Please refere to official Android docs or ask your questions on SO.

@zcelaloglu
Copy link
Author

no fragment attached to activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants