Errata in Listing 17.3


I bought the Kindle edition of Android Programming yesterday. I think i found an errata:
In Listing 17.3 Saving persistently in CrimeLab

I think is missing in the

private CrimeLab(Context appContext) { ... .. . mSerializer = new CriminalIntentJSONSerializer(appContext,FILENAME); }


It looks like we already have that item in the errata. Thanks for the sharp eye, though! Let us know if you find anything else.


Note that the text says that the creation of the instance should be done in the onCreate method, which does not exist for CrimeLab. As suggested above, the instance of CriminalIntentJSONSerializer can be created in the constructor.


Nice catch! Added.


I had the same problem here today…Well I have a doubt here…to solve the issue I did this …(after I saw this post I felt it was highly unnecessary though)

I created this class to get the app context anywhere inside/outside the activity:

[b]public class MyContext extends Application
private static Context context;
public void onCreate()
context = get ApplicationContext();

public static Context getAppContext()
return context;
and then I used it in

public class CrimeLab{…

private CriminalIntentJSONSerilaizer mSerializer = new CriminalIntentJSONSerializer(MyApp.getAppContext(),FILENAME)
and this seems to be not working…why ? I know I did something really dumb…what is the mistake here…?


Try initializing your JSON serializer in the constructor instead of in a static initializer.


small errata:
In 17.3 I think the following lines don’t need to be bold. They are already there:

private static CrimeLab sCrimeLab; private Context mAppContext;