last day (14 days later) » 

4:33 AM
0
Q: Android - findViewById always return null on Nougat but not on below version

WebsterI always get an error when reach this line of code : pickerDialog.getDatePicker().findViewById(button).setVisibility(View.GONE); the button is not null, but when I debug, I got an exception says java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVi...

 
How are you getting the button ID?
 
hi guys, please see my edited post above. Tks
@PratikButani , I wrote it on the above post
 
What do you expect R.id.button to point to? I mean, that's an ID in your app. Why are you looking for it in a DatePicker? Have you customized it?
 
@MikeM. , i expect it to point to the button, it's a customized button, so when the user click on it, it will show a pop up of month & year. it works well on below version but not for nougat
 
I really don't see how it works on any version. How are you getting your customized Button inside a DatePicker in a DatePickerDialog? Are you sure you're looking in the right place? That is, are you sure you're calling findViewById() on the right thing?
 
4:33 AM
@MikeM. , please see my edited post above. So the flow is, when the button click, it will show a datepickerdialog
 
If you mean the Button we're talking about is the one that opens the DatePickerDialog, then your code doesn't make sense. pickerDialog.getDatePicker().findViewById(button) - That means you're looking for that Button inside the DatePicker that is inside the DatePickerDialog. How can that Button be there, if it's what opens the Dialog?
 
hi, you there?
so it
so it's on a Fragment, and it calls another fragment
 
5:07 AM
No, I wasn't here. I am now.
I don't really know what you mean, exactly, but if that Button is in a Fragment, you're calling findViewById() on the wrong thing. You need to find it in the Fragment, not in the Dialog's DatePicker.
Just find the Button when you setup the Fragment's View initially, and only call setVisibility() in that method. Don't try to find it there.
I'm on a phone, right now, and chat doesn't work very well. If you have further issues, just edit your question with more details, including the `Fragment` layout and `onCreateView()` method.
Later.
 

last day (14 days later) »