title: I cannot get ContentProvider info from SQLite db - Android
body: <p></p>
  
  <p>public class Cliente extends SQLiteOpenHelper{</p>
  
  <pre><code>public Cliente(Context context, String name, CursorFactory factory,
          int version) {
      super(context, name, factory, version);
      // TODO Auto-generated constructor stub
  }
  
  private String query = "CREATE TABLE Clientes "+
  "(_id INTEGER PRIMARY KEY AUTOINCREMENT,"+
  " nombre TEXT, "+
  " telefono TEXT, "+
  " email TEXT )";
  
  
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      // TODO Auto-generated method stub
      db.execSQL(query);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      // TODO Auto-generated method stub
      db.execSQL("DROP TABLE Clientes");
      db.execSQL(query);
  }
  </code></pre>
  
  <p>}</p>
  
  <p></p>
  
  <p>public class ClienteProvider extends ContentProvider{</p>
  
  <pre><code>public static final Uri CONTENT_URI = Uri.parse("content://com.inkadroid.ejemplocp/Cliente");
  
  //Nombres de columnas
  
  public static final String COL_NOMBRE = "nombre";
  public static final String COL_TELEFONO = "telefono";
  public static final String COL_EMAIL = "email";
  
  
  private Cliente db;
  private static final String BD_NOMBRE = "BD_Ventas";
  private static final int BD_VERSION = 1;
  private static final String TABLA_CLIENTES = "Clientes";
  
  //UriMatcher acceso a una tabla o registro especifico
  private static final int CLIENTES = 1; 
  private static final int CLIENTES_ID = 2; 
  private static final UriMatcher uriMatcher;
  static {
      uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 
      uriMatcher.addURI("com.inkadroid.ejmeplocp2", "Clientes", CLIENTES); 
      uriMatcher.addURI("com.inkadroid.ejmeplocp2", "Clientes/#", CLIENTES_ID);
  }
  
  @Override
  public boolean onCreate() {
      // TODO Auto-generated method stub
      return true;
  }
  
  @Override
  public Cursor query(Uri uri, String[] projection, String selection,
          String[] selectionArgs, String sortOrder) {
      // TODO Auto-generated method stub
      //Si es una consulta a un ID concreto construimos el WHERE
      String where = selection;
  
      Log.e("Select", where);
  
      if(uriMatcher.match(uri) == CLIENTES_ID){
  
          Log.e("URI", uri+"");
          where = "_id=" + uri.getLastPathSegment();
      }
  
      SQLiteDatabase access= db.getWritableDatabase();
      Cursor c = access.query(TABLA_CLIENTES, projection, where, selectionArgs, null, null,
      sortOrder);
      Log.e("TABLA_CLIENTES", TABLA_CLIENTES);
      Log.e("where", where);
  
      return c;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p></p>
  
  <p>public class MainActivity extends Activity {</p>
  
  <pre><code>String[] projection = new String[]{"codigo","nombre","telefono","email"};
  String selection = "SELECT * FROM Clientes ;";
  String[] selectionArgs = null;
  String sortOrder = null;
  
  
  ClienteProvider clienteProvider;
  
  ContentResolver resolver;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Cliente cliente = new Cliente(this, "BD_Ventas", null, 1);
      SQLiteDatabase conexion = cliente.getWritableDatabase();
  
      for(int i=0; i&lt;10;i++){
          conexion.execSQL("INSERT INTO Clientes (nombre,telefono,email) values ('cliente"+i+"','977915615','cliente@gmail.com')");
  
      }
  
      Cursor cursor = resolver.query(ClienteProvider.CONTENT_URI,projection,selection,selectionArgs,sortOrder);
  
  
      while (cursor.moveToNext()) {
  
          do {
              String codigo= cursor.getString(0);
              Log.e("Codigo", codigo);
              String nombre= cursor.getString(1);
              Log.e("nombre", nombre);
              String telefono = cursor.getString(2);
              Log.e("telefono", telefono);
              String email = cursor.getString(3);
              Log.e("email", email);
  
              String inString = codigo + " " + nombre + " " + telefono +" " + email + " ."; 
              Log.e("Sentencia", inString);
              Toast.makeText(this, inString, Toast.LENGTH_LONG).show();
  
          } while(cursor.moveToNext());
  
  
  
      }    
  
      conexion.close();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p></p>
  
  <p>01-02 02:01:56.710: E/AndroidRuntime(13717): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inkadroid.ejemplocp/com.inkadroid.ejemplocp.MainActivity}: java.lang.NullPointerException</p>