CrimeListFragment shows empty after killing the app


#1

I am following through the book and I believe I have everything set up correctly (I compared against book/downloaded class files). I am able to save the list of crimes to internal storage. I have set up a toast and a debug entry that gets logged which I see each time I add a new crime.

However, when I kill my application (either through eclipse or via Device Settings > App > Force Stop) and then re-launch it, I always start with an empty view on the CrimeListFragment. For some reason, I am unable to load the crimes from internal storage.

I am checking in the constructor for CrimeLab as to whether any crimes are persisted to internal storage. If not, I create an a new ArrayList. Here is the code:
[color=#0040FF]private CrimeLab(Context appContext) {
mAppContext = appContext;
//mCrimes = new ArrayList();

	mSerializer = new CriminalIntentJSONSerializer(mAppContext,FILENAME);
	
	try {
		mCrimes = mSerializer.loadCrimes();
	} 
	catch (Exception e) {
		// TODO Auto-generated catch block
		mCrimes = new ArrayList<Crime>();			
		e.printStackTrace();
	}[/color]

Any ideas as to what might be going wrong? I have been stuck with this for over 2 hours now. Any help/suggestions will be highly appreciated.
Thanks!


#2

I figured out the problem. In Crime.java I was trying to cast JSON_ID and JSON_DATE strings to UUID and Date respectively. I corrected & it all worked fine.
//mID = (UUID) json.get(JSON_ID);
mID = UUID.fromString(json.getString(JSON_ID));

//mDate = (Date) json.get(JSON_DATE);
mDate = new Date(json.getLong(JSON_DATE));

Commented out code was how I had it set up initially.