CrimeAdapter issue


#1

Hi guys.

I think I’m having issues with getView in CrimeAdapter. the constructor works fine since it’s essentially the same thing as the previous ArrayAdapter adapter call we made. All the code works fine up to the CrimeAdapter constructor. But once I put in the getView code, CriminalIntent force closes immediately.

Edit: If we put in 0 for the layout ID, then when is the layout ID chosen? I don’t know where else the problem with my code is.

Also, when I ran CriminalIntent with CrimeActivity as the launcher, my phone always booted the program without me initiating it on the phone. However after changing the launcher to CrimeListActivity, I always have to manually launch the app on the phone.

Here’s the code for getView, which should be identical to what the book says. I doublechecked pretty much all the code for this app with the solutions and most of it is similar, but eh.

[code]@Override
public View getView (int position, View convertView, ViewGroup parent) {
// if view isn’t given, 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;
	}[/code]

Here’s code for the manifest file as well:

[code]<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.bignerdranch.android.criminalintent.CrimeListActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.bignerdranch.android.criminalintent.CrimeActivity"
        android:label="@string/app_name" >
    </activity>
</application>
[/code]

#2

I tried your code in to my project and everything worked as expected.

Is there anything interesting in the Console or LogCat outputs?


#3

1- Stack trace! Post a stack trace from logcat, and it will be much easier for us to figure out what went wrong.

2- Double check your layout file. Your adapter looks fine, but you could have problems if your layout file doesn’t have the right widgets.


#4

Stupidest error, I didn’t capitalize B in CheckBox in the layout file. :cry: Thanks guys.

I still can’t get the program to load on its own though, once I switch the launcher to CrimeListActivity. I always have to manually open the app on my phone once I run it on eclipse. It’s not that big of a deal, and if that’s supposed to happen, that’s great, but I’d love to hear any ideas you have.


#5

Check your launch configuration - it may not be configured to automatically fire up the app once it is installed.