-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
- Loading branch information
There are no files selected for viewing
22 comments
on commit 07f3866
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR: Inner class cant have static declaration
LINE 59:
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, PATH_PETS);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed its working fine here. can you show some code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same error: Here's the code
public class PetsEntry implements BaseColumns {
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT,PATH_PETS);
public static final String TABLE_NAME = "Pets";
public static final String COLUMN_ID = BaseColumns._ID;
public static final String COLUMN_PET_NAME = "name";
public static final String COLUMN_PET_BREED = "breed";
public static final String COLUMN_PET_GENDER = "gender";
public static final String COLUMN_PET_WEIGHT = "weight";
public static final int GENDER_MALE = 1;
public static final int GENDER_FEMALE = 2;
public static final int GENDER_UNKNOWN = 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error resolved 👍 you simply have to declare Petentry class as static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel quite comfortable with two different constants for the pets table name, namely
public static final String PATH_PETS = "pets";
and
public static final String TABLE_NAME = "pets";
Is there any particular reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dfdazac you may have two names(you actual name and a nickname) but both of used to call you at different places and with different references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Devenc234 @dfdazac correct me if I'm wrong but you can't have the URI contain a name different than your database table name.
so both strings are and must be the same which in turn makes no sense why they are 2 and not 1
it should be like this:
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Devenc234 I have the same argument as given by @Amr-Y above. U cant have a real and a pet name for a table in this case. PATH_PETS and TABLE_NAME have to be the same, so why two separate variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Devenc234 is right, we all have like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a significant reason why the first 3 constants are placed outside of the PetEntry class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albertoastroc, because there could be more than 1 table and you or other developers will clearly see in the future that those constants are general and available for use .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank GOD no errors currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same way.. why 2 constants with same value?? We will probably find out later 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONTENT_URI is never used, why? (Im on lesson 4.16)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between PATH_PETS (line 50) and TABLE_NAME (line 62)? I mean, their names are different obviously, but the values are the same, they are all pointing to the table which is also the name of the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice Work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a bit diff app. Anyways..
isn't that better to put CONTENT_URI like this:
public final static Uri CONTENT_URI_PETS = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME);
instead of:
public final static Uri CONTENT_URI_PRACTITIONERS = Uri.withAppendedPath(BASE_CONTENT_URI, PATH_PETS);
this way we dont have add additional constant PATH_PETS .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the Uri for a single pet query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appfactoryCo see line 59, single pet query would be PetEntry.CONTENT_URI + rowId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a significant reason why the first 3 constants are placed outside of the PetEntry class?
@albertoastroc Because they don't really have a connection to a particular entry, i.e. table, but the database(i.e. outer Contract class) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appfactoryCo see line 59, single pet query would be PetEntry.CONTENT_URI + rowId.
YES you are right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//Next, we concatenate the CONTENT_AUTHORITY constant with the scheme “content://” we will create
// the BASE_CONTENT_URI which will be shared by every URI associated with PetContract:
public static final String CONTENT_AUTHORITY = "com.example.android.pets";
//To make this a usable URI, we use the parse method which takes in a URI string and returns a Uri.
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
//This constants stores the path for each of the tables which will be appended to the base content URI.
public static final String PATH_PETS = "pets";
//Complete CONTENT_URI
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, PATH_PETS);