Add import for CrimeTable not working


#1

Hello, I’m on the “Adding a CrimeTable import” section and I’ve noticed that what I’m importing is not what the books is stating.

This is what it is importing:

import database.CrimeDbSchema.CrimeDbSchema.CrimeTable;

The book states:

import com.bignerdranch.android.criminalintent.database.CrimeDbSchema.CrimeTable;

I can’t think of what I’ve done wrong.

This is the schema:


package database.CrimeDbSchema;

public class CrimeDbSchema {
    public static final class CrimeTable {
        public static final String NAME = "crimes";

        public static final class Cols {
            public static final String UUIID = "uuid";
            public static final String TITLE = "title";
            public static final String DATE = "date";
            public static final String SOLVED = "solved";
        }
    }
} ```


This is the CrimeBaseHelper.java:


```package database.CrimeDbSchema;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import database.CrimeDbSchema.CrimeDbSchema.CrimeTable;

public class CrimeBaseHelper extends SQLiteOpenHelper {

    private static final int VERSION = 1;
    private static final String DATABASE_NAME = "crimeBase.db";

    public CrimeBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + CrimeTable.NAME);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}```


For CrimeLab.java:


```package com.bignerdranch.android.criminalintent;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

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

import database.CrimeDbSchema.CrimeBaseHelper;

public class CrimeLab {
    private static CrimeLab sCrimeLab;

    private List<Crime> mCrimes;
    private Context mContext;
    private SQLiteDatabase mDatabase;

    public static CrimeLab get(Context context) {
        if (sCrimeLab == null) {
            sCrimeLab = new CrimeLab(context);
        }
        return sCrimeLab;
    }

    private CrimeLab(Context context) {

        mContext = mContext.getApplicationContext();
        mDatabase = new CrimeBaseHelper(mContext)
                .getWritableDatabase();
        mCrimes = new ArrayList<>();
    }

    public void addCrime(Crime c) {


        mCrimes.add(c);
    }

    public List<Crime> getCrimes() {
        return mCrimes;
    }

    public Crime getCrime(UUID id) {
        for (Crime crime : mCrimes) {
            if (crime.getId().equals(id)) {
                return crime;
            }
        }
        return null;
    }
}```

#2

Please double check your package name.


#3

Thanks for the reply.

Regarding the package name, so it should be

package com.bignerdranch.android.criminalintent.database.CrimeDbSchema.CrimeTable

Rather than package database.CrimeDbSchema ?

I had assumed it was the second because we had to create these two files within its own package, rather than the com.bignerdranch.android.criminalintent.


#4

It should be “com.bignerdranch.android.criminalintent.database”.