Crime Adapter Issue


#1

I am having problems making this work. The application starts up briefly and then crashes. It worked until I changed to the Crime Adapter. Here is my code and a LogCat Stack Trace. I would really appreciate any help you could give.

This is my CrimeListActivity code

package com.bignerdranch.android.criminalintent;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

public class CrimeListFragment extends ListFragment {
	
	private static final String TAG = "CrimeListFragment";
	private ArrayList<Crime> mCrimes;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		getActivity().setTitle(R.string.crimes_title);
		mCrimes = CrimeLab.get(getActivity()).getCrimes();
		
		CrimeAdapter adapter = new CrimeAdapter(mCrimes);
		setListAdapter(adapter);
	}
	
	@Override
	public void onListItemClick(ListView I, View v, int position, long id) {
		Crime c = ((CrimeAdapter)getListAdapter()).getItem(position);
		Log.d(TAG, c.getTitle() + " was clicked");
	}
	private class CrimeAdapter extends ArrayAdapter<Crime>{
		
		public CrimeAdapter (ArrayList<Crime> crimes){
			super(getActivity(), 0, crimes);
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent){
			//If we weren't given a view, inflate one
			if (convertView == null){
				convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
			}
			
			//Configure the view for this Crime
			Crime c = getItem(position);
			
			TextView titleTextView =
					(TextView)convertView.findViewById(R.id.crime_list_item_titleTextView);
			titleTextView.setText(c.getTitle());
			
			TextView dateTextView =
					(TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
			dateTextView.setText(c.getDate().toString());
			CheckBox solvedCheckBox =
					(CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
			solvedCheckBox.setChecked(c.isSolved());
			return convertView;
		}
	}
	

	
}

Here is the LogCat stack trace

07-13 14:14:38.497: D/dalvikvm(29459): Late-enabling CheckJNI
07-13 14:14:40.937: D/libEGL(29459): loaded /system/lib/egl/libEGL_tegra.so
07-13 14:14:41.137: D/libEGL(29459): loaded /system/lib/egl/libGLESv1_CM_tegra.so
07-13 14:14:41.207: D/libEGL(29459): loaded /system/lib/egl/libGLESv2_tegra.so
07-13 14:14:41.367: D/OpenGLRenderer(29459): Enabling debug mode 0
07-13 14:14:41.417: D/AndroidRuntime(29459): Shutting down VM
07-13 14:14:41.417: W/dalvikvm(29459): threadid=1: thread exiting with uncaught exception (group=0x41cae930)
07-13 14:14:41.437: E/AndroidRuntime(29459): FATAL EXCEPTION: main
07-13 14:14:41.437: E/AndroidRuntime(29459): android.view.InflateException: Binary XML file line #26: Error inflating class Textview
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at com.bignerdranch.android.criminalintent.CrimeListFragment$CrimeAdapter.getView(CrimeListFragment.java:45)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.AbsListView.obtainView(AbsListView.java:2159)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.ListView.makeAndAddView(ListView.java:1831)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.ListView.fillDown(ListView.java:674)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.ListView.fillFromTop(ListView.java:735)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.ListView.layoutChildren(ListView.java:1652)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.AbsListView.onLayout(AbsListView.java:1994)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.View.layout(View.java:14008)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewGroup.layout(ViewGroup.java:4373)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.Choreographer.doFrame(Choreographer.java:532)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.os.Handler.handleCallback(Handler.java:725)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.os.Handler.dispatchMessage(Handler.java:92)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.os.Looper.loop(Looper.java:137)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at java.lang.reflect.Method.invokeNative(Native Method)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at java.lang.reflect.Method.invoke(Method.java:511)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at dalvik.system.NativeStart.main(Native Method)
07-13 14:14:41.437: E/AndroidRuntime(29459): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Textview" on path: /data/app/com.bignerdranch.android.criminalintent-2.apk
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-13 14:14:41.437: E/AndroidRuntime(29459): 	
07-13 14:14:41.477: D/dalvikvm(29459): GC_CONCURRENT freed 249K, 6% free 7478K/7876K, paused 5ms+4ms, total 33ms

#2

It looks like the problem is in your layout file. This line in your stack trace:

07-13 14:14:41.437: E/AndroidRuntime(29459): android.view.InflateException: Binary XML file line #26: Error inflating class Textview

This probably did not jump out at you, but it jumped out to me. The error here is that you’ve got “Textview” in your layout file, instead of “TextView”. Eclipse doesn’t verify that the casing on the element name is correct. It will just blow up at runtime instead.


#3

Thanks. I knew it had to be something simple. I missed that.