I was dealing with an issue where my CriminalIntent app would crash on launch due to a NullPointerException
. The stack trace led me to the second line of my onCreateView()
method in my CrimeFragment.java
where I tried to initialize my mTitleField
object using the .findViewById()
method. I realized that (at least in Android Studio 3.0.1) the autocomplete for the onCreateView()
method included different code than what was in the book.
It took me a while to notice, but AS inserted the following line:
return super.onCreateView(inflater, container, savedInstanceState);
Which I edited to break the return statement and the initialization of the View
object into two lines and continued happily with the book, since the potential for .
The proper line displayed in the book is
View v = inflater.inflate(R.layout.fragment_crime, container, false);
which is followed (after implementing all other methods in the chapter) by
return v;
This is a simple error others may find themselves dealing with so I thought I would share my experience with it to perhaps help others in the future. Good luck and be careful when using autocomplete!