Errata in Listing 17.3


#1

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); }


#2

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.


#3

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.


#4

Nice catch! Added.


#5

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;
}
}
[/b]
and then I used it in CrimeLab.java

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…?


#6

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


#7

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;