Cannot find error


#1

Hi there, the app worked fine at the end of chapter 8, but by the first listing(9.1) in chapter 9 I had issues. Eclipse says that “the value of the field CrimeLab.mApp.Context is not used.” The below is in CrimeLab.java

package com.bignerranch.android.criminalintent;

import java.util.ArrayList;
import java.util.UUID;

import android.content.Context;

public class CrimeLab {
	private ArrayList<Crime> mCrimes;
	
	private static CrimeLab sCrimeLab;
	private Context mAppContext;
	
	private CrimeLab(Context appContext) {
		mAppContext = appContext;
		mCrimes = new ArrayList<Crime>();
		for (int i = 0; i <100; i++) {
			Crime c = new Crime();
			c.setTitle("Crime #" + i);
			c.setSolved(i % 2 == 0); //Every other one
			mCrimes.add(c);
		}
	}
	public static CrimeLab get(Context c) {
		if (sCrimeLab == null) {
			sCrimeLab = new CrimeLab(c.getApplicationContext());
		}
		return sCrimeLab;
	}
	public ArrayList<Crime> getCrimes() {
		return mCrimes;
	}
	public Crime getCrime(UUID id) {
		for (Crime c : mCrimes) {
			if (c.getId().equals(id))
				return c;
		}
		return null;
	}
}

Then the same issue in CrimeListFragment.java. It states, “the value of the field CrimeListFragment.mCrimes is not used.”

package com.bignerranch.android.criminalintent;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.ListFragment;

public class CrimeListFragment extends ListFragment {
	private ArrayList<Crime> mCrimes;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getActivity().setTitle(R.string.crimes_title);
		mCrimes = CrimeLab.get(getActivity()).getCrimes();
	}
}

Here is the logCat info. I hope I am inputting it correctly.

07-16 01:41:06.060: D/AndroidRuntime(721): Shutting down VM 07-16 01:41:06.060: W/dalvikvm(721): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-16 01:41:06.090: E/AndroidRuntime(721): FATAL EXCEPTION: main 07-16 01:41:06.090: E/AndroidRuntime(721): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.bignerranch.android.criminalintent/com.bignerranch.android.criminalintent.CrimeListACtivity}: java.lang.ClassNotFoundException: com.bignerranch.android.criminalintent.CrimeListACtivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerranch.android.criminalintent-1.apk] 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.os.Handler.dispatchMessage(Handler.java:99) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.os.Looper.loop(Looper.java:123) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-16 01:41:06.090: E/AndroidRuntime(721): at java.lang.reflect.Method.invokeNative(Native Method) 07-16 01:41:06.090: E/AndroidRuntime(721): at java.lang.reflect.Method.invoke(Method.java:521) 07-16 01:41:06.090: E/AndroidRuntime(721): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-16 01:41:06.090: E/AndroidRuntime(721): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-16 01:41:06.090: E/AndroidRuntime(721): at dalvik.system.NativeStart.main(Native Method) 07-16 01:41:06.090: E/AndroidRuntime(721): Caused by: java.lang.ClassNotFoundException: com.bignerranch.android.criminalintent.CrimeListACtivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerranch.android.criminalintent-1.apk] 07-16 01:41:06.090: E/AndroidRuntime(721): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 07-16 01:41:06.090: E/AndroidRuntime(721): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 07-16 01:41:06.090: E/AndroidRuntime(721): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-16 01:41:06.090: E/AndroidRuntime(721): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 07-16 01:41:06.090: E/AndroidRuntime(721): ... 11 more

Sorry, I know thats a lot, probably best to help find the issue though. Thanks for any help.


#2

The two issues you point out from Eclipse aren’t the problem. These are both warnings - they will go away as you go further into the exercise, but they are harmless.

You can see the actual issue in your stack trace - here:

07-16 01:41:06.090: E/AndroidRuntime(721): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.bignerranch.android.criminalintent/com.bignerranch.android.criminalintent.CrimeListACtivity}: java.lang.ClassNotFoundException: com.bignerranch.android.criminalintent.CrimeListACtivity in loader dalvik.system.PathClassLoader[/data/app/com.bignerranch.android.criminalintent-1.apk]

See where the issue is?