Good afternoon to all,
I started two weeks ago a sequence of studies on programming for Android. I'm studying for this book.
I bought it a while ago and thank God I finally arrived on page 341 which is database.
It has a class called car, I understand object-oriented, but I have never seen a class as strange as that
package com.example.googleplay.model;
import java.net.URI;
import android.content.ContentUris;
import android.net.Uri;
import android.provider.BaseColumns;
public class Carro {
public static String[] colunas = new String[] { Carros._ID, Carros.NOME,
Carros.PLACA, Carros.ANO };
public static final String AUTHORITY = "com.example.googleplay.model.carro";
public long id;
public String nome;
public String placa;
public int ano;
public Carro() {
}
public Carro(String nome, String placa, int ano) {
super();
this.nome = nome;
this.placa = placa;
this.ano = ano;
}
public Carro(long id, String nome, String placa, int ano) {
super();
this.id = id;
this.nome = nome;
this.placa = placa;
this.ano = ano;
}
public static final class Carros implements BaseColumns {
private Carros() {
}
}
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/carros");
public static final String CONTENT_TYPE = "vnd.android.curso.dir/vnd.google.carros";
public static final String CONTENT_ITEM_TYPE = "vnd.android.curso.item/vnd.google.carros";
public static final String DEFAULT_SORT_ORDER = "_id_ASC";
public static final String NOME = "nome";
public static final String ANO = "ano";
public static final String PLACA = "placa";
public static Uri getUriId() {
Uri uriCarro = ContentUris.withAppendedId(Carros.CONTENT_URI, id);
return uriCarro;
}
@Override
public String toString() {
return "Nome: " + nome + ", Placa " + placa + ", Ano " + ano;
}
}
I will only comment on the parts that have gone red.
public static String[] colunas = new String[] { Carros._ID, Carros.NOME,
Carros.PLACA, Carros.ANO };
In order to exist Carros
it was necessary that there was a class called Carros
, but in the book project there is no class called Carros
, it recognized only _ID
The oddest thing is that Carros
was able to see _ID
.
So I really can not explain.
This other piece of code is also red:
public static Uri getUriId() {
Uri uriCarro = ContentUris.withAppendedId(Carros.CONTENT_URI, id);
return uriCarro;
}
What went red was CONTENT
.
I understand that it is complicated to have to help without having access to the book, but even so I posted, I hope to receive some help.