Anybody got any ideas?

I thought I had it figured out with the database but that didn't work.

It seems that either my naming of the CONTENT_URI or something to do with
that is wrong or else a database/table for the settings never actually gets
created? if theres no data there for the content provider would I get that
error?

Or is it actually something to do with the CONTENT_URI?

On Mon, Dec 21, 2009 at 3:56 PM, [email protected] <[email protected]>wrote:

> Hi,
>
> I have written the following content provider, but when I try to pull
> information from it into an array, I get the following error:
>
> 12-21 15:14:18.627: ERROR/ActivityThread(1160): Failed to find
> provider info for cicero.org.provider.CiceroContentProvider
>
>
> I presume its something to do with my naming of the CONTENT_URI or
> something? I'm not quite sure how it works so could anyone explain a
> bit and spot what I have done wrong?
>
> This is what I have in the manifest:
>
> XML:
> <provider android:name=".CiceroContentProvider"
>
> android:authorities="cicero.org.provider.CiceroContentProvider" />
>
>
> Java:
> public class CiceroContentProvider extends ContentProvider{
>
>     //URI
>     public static final Uri CONTENT_URI =
>                                   Uri.parse("content://
> cicero.org.provider.CiceroContentProvider");
>
>     //Underlying database
>
>     private SQLiteDatabase settingsDB;
>
>     private static final String TAG = "CiceroProvider";
>     private static final String DATABASE_NAME = "cicero_settings.db";
>     private static final int DATABASE_VERSION = 1;
>     private static final String SETTINGS_TABLE = "settings";
>
>
>     //Column names
>     public final static String _ID = "_id";
>     public final static String VOIPUSERNAME = "voipusername";
>     public final static String VOIPAUTHID = "voipauthid";
>     public final static String PASSWORD = "password";
>     public final static String SIPPROXYSERVER = "sipproxyserver";
>     public final static String SIPREGISTRAR = "sipregistrar";
>     public final static String SIPREALM = "siprealm";
>     public final static Integer EXPIRESTIME =30;
>
>     //column indexes
>     public static final int VOIPUSERNAME_COL = 1;
>     public static final int VOIPAUTHID_COL = 2;
>     public static final int PASSWORD_COL = 3;
>     public static final int SIPPROXYSERVER_COL = 4;
>     public static final int SIPREGISTRAR_COL = 5;
>     public static final int SIPREALM_COL = 6;
>     public static final int EXPIRESTIME_COL = 7;
>
>     //helper class
>     private static class settingsDatabaseHelper extends
> SQLiteOpenHelper{
>
>          private static final String CREATE_SETTINGS_TABLE
>          = "CREATE TABLE tbl_settings(" +
>                    "_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
>                    "VOIPUSERNAME TEXT," +
>                    "VOIPAUTHID TEXT," +
>                    "PASSWORD TEXT," +
>                    "SIPPROXYSERVER TEXT," +
>                    "SIPREGISTRAR TEXT," +
>                    "SIPREALM TEXT," +
>                    "EXPIRESTIME INTEGER);";
>
>          public settingsDatabaseHelper(Context context, String name,
>                    CursorFactory factory, int version) {
>               super(context, name, factory, version);
>
>          }
>
>          @Override
>          public void onCreate(SQLiteDatabase db) {
>               db.execSQL(CREATE_SETTINGS_TABLE);
>
>          }
>
>          @Override
>          public void onUpgrade(SQLiteDatabase db, int oldVersion, int
> newVersion) {
>               Log.w(TAG, "Upgrading database from version " +
> oldVersion + " to " +
>                          newVersion + ", which will destroy all old
> data");
>
>               db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
>               onCreate(db);
>
>          }
>
>     }
>
>     //end helper class
>
>
>     private static final int SETTINGS = 1;
>     private static final int SETTINGS_ID = 2;
>
>     private static final UriMatcher uriMatcher;
>
>     static{
>          uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
>          uriMatcher.addURI
> ("cicero.org.provider.CiceroContentProvider", "settings", SETTINGS);
>          uriMatcher.addURI
> ("cicero.org.provider.CiceroContentProvider", "settings/#",
> SETTINGS_ID);
>     }
>
>
>     @Override
>     public String getType(Uri uri) {
>          switch(uriMatcher.match(uri)){
>          case SETTINGS:
>               return "vnd.android.cursor.dir/
> vnd.org.CiceroContentProvider";
>          case SETTINGS_ID:
>               return "vnd.android.cursor.item/
> vnd.org.CiceroContentProvider";
>          default:
>               throw new IllegalArgumentException("Unsupported URI: "
> + uri);
>          }
>
>     }
>
>
>
>     @Override
>     public boolean onCreate() {
>          Context context = getContext();
>
>          settingsDatabaseHelper dbHelper;
>          dbHelper = new settingsDatabaseHelper(context,
> DATABASE_NAME, null, DATABASE_VERSION);
>
>          SQLiteDatabase settingsDB = dbHelper.getWritableDatabase();
>          return (settingsDB == null) ? false : true;
>     }
>
>     @Override
>     public Cursor query(Uri uri, String[] projection, String
> selection,
>               String[] selectionArgs, String sortOrder) {
>
>          SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
>
>          qBuilder.setTables(SETTINGS_TABLE);
>
>          switch(uriMatcher.match(uri)){
>
>          case SETTINGS_ID:
>               qBuilder.appendWhere(_ID + "=" + uri.getPathSegments
> ().get(1));
>               break;
>          default:
>               break;
>
>          }
>
>          String orderBy;
>
>          if(TextUtils.isEmpty(sortOrder)){
>
>               orderBy = VOIPUSERNAME;
>
>          }
>          else{
>
>               orderBy = sortOrder;
>
>          }
>
>          Cursor c = qBuilder.query(settingsDB, projection, selection,
> selectionArgs, null, null, orderBy);
>
>          c.setNotificationUri(getContext().getContentResolver(),
> uri);
>
>          return c;
>     }
>
>     @Override
>     public int update(Uri uri, ContentValues values, String
> selection,
>               String[] selectionArgs) {
>
>          int count;
>
>          switch(uriMatcher.match(uri)){
>
>          case SETTINGS:
>               count = settingsDB.update(SETTINGS_TABLE, values,
> selection, selectionArgs);
>               break;
>
>          case SETTINGS_ID:
>               String segment = uri.getPathSegments().get(1);
>               count = settingsDB.update(SETTINGS_TABLE, values, _ID +
> "=" + segment + (!TextUtils.isEmpty(selection) ? " AND (" + selection
> + ')' : ""), selectionArgs);
>               break;
>
>          default:
>               throw new IllegalArgumentException("Unkonwn URI " +
> uri);
>          }
>          getContext().getContentResolver().notifyChange(uri, null);
>          return count;
>     }
>
>     @Override
>     public int delete(Uri uri, String selection, String[]
> selectionArgs) {
>
>          int count;
>
>          switch(uriMatcher.match(uri)){
>
>          case SETTINGS:
>               count = settingsDB.delete(SETTINGS_TABLE, selection,
> selectionArgs);
>               break;
>
>          case SETTINGS_ID:
>               String segment = uri.getPathSegments().get(1);
>               count = settingsDB.delete(SETTINGS_TABLE, _ID + "=" +
> segment + (!TextUtils.isEmpty(selection) ? " AND (" + selection +
> ')':""), selectionArgs);
>               break;
>
>          default:
>               throw new IllegalArgumentException("Unsupported URI: "
> + uri);
>          }
>          getContext().getContentResolver().notifyChange(uri, null);
>          return count;
>     }
>
>     @Override
>     public Uri insert(Uri _uri, ContentValues _initialValues) {
>          long rowId = settingsDB.insert(SETTINGS_TABLE,
> "settings",_initialValues);
>
>          if(rowId > 0){
>
>               Uri uri = ContentUris.withAppendedId(CONTENT_URI,
> rowId);
>               getContext().getContentResolver().notifyChange(uri,
> null);
>               return uri;
>          }
>          throw new SQLException("Failed to insert row into " + _uri);
>
>     }
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to