Lisa Austin wrote:I then tried to implement the ListView on one of the Fragments and I receive the following Fatal Exception
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Pete Letkeman wrote:
Lisa Austin wrote:I then tried to implement the ListView on one of the Fragments and I receive the following Fatal Exception
There are four items in the list to choose from and this seems to only happen when you click on the first element in the list "Food".
The other three elements seems to work fine, well they do not produce this error at least.
What version of Android are you targeting?
You may not be aware of this, but Kotlin has some improvements over Java and it is officially supported for Android development by Google.
You can have a project which has both Kotlin and Java source files, which is a good way to migrate away from Java and to learn Kotlin.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Pete Letkeman wrote:The problem is with this line of code in BBQFragment.java Once you provide the correct value for inflater you will get the results that you want.
Pete Letkeman wrote:The problem is with this line of code in BBQFragment.java Once you provide the correct value for inflater you will get the results that you want.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
To get past the NullPointerException you only need to change the value of rootView and nothing else. After that you get a "working" program.Lisa Austin wrote:And the example showed the container's XML was what contained the fragment ( in this case NumbersFragment() ).
My code doesn't specify anything to contain the fragment, I just want to display it. Am I on the right track by any chance?
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Pete Letkeman wrote:The rootView value that you had/have does not have any child view elements named bbq_list_view.
Essentially this is what happens:
1) Android loads R.layout.locations_list on line 35.
2) On line 42 Android looks for an element named bbq_list_view in the locations_list view.
3) Android is unable to find that view, so Android returns a null.
4) Result you get a NullPointerException as you have experienced.
The solution is to have the rootView inflate the view which contains the child element named bbq_list_view.
It did take me a bit to get to the correct end result.
Here are the general debugging steps I used:
1) Try out the program to see if the produces the same error/result as you
2) From the user experience find out where the error seems to happen by commenting out some lines of code.
- This lead me to the post where I mention the problem with FoodActivity.java
3) Narrow down the error even more by jumping down further into the code/classes which lead me to the post about "listView" return null.
4) Find the code which should have setup the listView to see how that was loaded.
5) Change the value of the rootView to load in a different view (the view with bbq_list_view).
I used the shortcut "logd" in Android Studio many times to print intermediate values.
Pete Letkeman wrote:
To get past the NullPointerException you only need to change the value of rootView and nothing else. After that you get a "working" program.Lisa Austin wrote:And the example showed the container's XML was what contained the fragment ( in this case NumbersFragment() ).
My code doesn't specify anything to contain the fragment, I just want to display it. Am I on the right track by any chance?
It may not do exactly what you want, but what would then be a business logic thing. For instance you may need to add in an onClick event or something like that, but that is a different problem.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
I am going to test your electrical conductivity with this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|