Cant find my content provider?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Cant find my content provider?

Postby Draffodx » Mon Dec 21, 2009 4:21 pm

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:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <provider android:name=".CiceroContentProvider"
  2.  
  3.                                                 android:authorities="cicero.org.provider.CiceroContentProvider" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class CiceroContentProvider extends ContentProvider{
  2.  
  3.  
  4.  
  5.         //URI
  6.  
  7.         public static final Uri CONTENT_URI =
  8.  
  9.                                                         Uri.parse("content://cicero.org.provider.CiceroContentProvider");
  10.  
  11.        
  12.  
  13.         //Underlying database
  14.  
  15.        
  16.  
  17.         private SQLiteDatabase settingsDB;
  18.  
  19.        
  20.  
  21.         private static final String TAG = "CiceroProvider";
  22.  
  23.         private static final String DATABASE_NAME = "cicero_settings.db";
  24.  
  25.         private static final int DATABASE_VERSION = 1;
  26.  
  27.         private static final String SETTINGS_TABLE = "settings";
  28.  
  29.        
  30.  
  31.        
  32.  
  33.         //Column names
  34.  
  35.         public final static String _ID = "_id";
  36.  
  37.         public final static String VOIPUSERNAME = "voipusername";
  38.  
  39.         public final static String VOIPAUTHID = "voipauthid";
  40.  
  41.         public final static String PASSWORD = "password";
  42.  
  43.         public final static String SIPPROXYSERVER = "sipproxyserver";
  44.  
  45.         public final static String SIPREGISTRAR = "sipregistrar";
  46.  
  47.         public final static String SIPREALM = "siprealm";
  48.  
  49.         public final static Integer EXPIRESTIME =30;
  50.  
  51.        
  52.  
  53.         //column indexes
  54.  
  55.         public static final int VOIPUSERNAME_COL = 1;
  56.  
  57.         public static final int VOIPAUTHID_COL = 2;
  58.  
  59.         public static final int PASSWORD_COL = 3;
  60.  
  61.         public static final int SIPPROXYSERVER_COL = 4;
  62.  
  63.         public static final int SIPREGISTRAR_COL = 5;
  64.  
  65.         public static final int SIPREALM_COL = 6;
  66.  
  67.         public static final int EXPIRESTIME_COL = 7;
  68.  
  69.        
  70.  
  71.         //helper class
  72.  
  73.         private static class settingsDatabaseHelper extends SQLiteOpenHelper{
  74.  
  75.  
  76.  
  77.                 private static final String CREATE_SETTINGS_TABLE
  78.  
  79.                 = "CREATE TABLE tbl_settings(" +
  80.  
  81.                                 "_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
  82.  
  83.                                 "VOIPUSERNAME TEXT," +
  84.  
  85.                                 "VOIPAUTHID TEXT," +
  86.  
  87.                                 "PASSWORD TEXT," +
  88.  
  89.                                 "SIPPROXYSERVER TEXT," +
  90.  
  91.                                 "SIPREGISTRAR TEXT," +
  92.  
  93.                                 "SIPREALM TEXT," +
  94.  
  95.                                 "EXPIRESTIME INTEGER);";       
  96.  
  97.                
  98.  
  99.                 public settingsDatabaseHelper(Context context, String name,
  100.  
  101.                                 CursorFactory factory, int version) {
  102.  
  103.                         super(context, name, factory, version);
  104.  
  105.                        
  106.  
  107.                 }
  108.  
  109.  
  110.  
  111.                 @Override
  112.  
  113.                 public void onCreate(SQLiteDatabase db) {
  114.  
  115.                         db.execSQL(CREATE_SETTINGS_TABLE);
  116.  
  117.                        
  118.  
  119.                 }
  120.  
  121.  
  122.  
  123.                 @Override
  124.  
  125.                 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  126.  
  127.                         Log.w(TAG, "Upgrading database from version " + oldVersion + " to " +
  128.  
  129.                                          newVersion + ", which will destroy all old data");
  130.  
  131.                        
  132.  
  133.                         db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
  134.  
  135.                         onCreate(db);
  136.  
  137.                        
  138.  
  139.                 }
  140.  
  141.                
  142.  
  143.         }
  144.  
  145.        
  146.  
  147.         //end helper class
  148.  
  149.        
  150.  
  151.        
  152.  
  153.         private static final int SETTINGS = 1;
  154.  
  155.         private static final int SETTINGS_ID = 2;
  156.  
  157.        
  158.  
  159.         private static final UriMatcher uriMatcher;
  160.  
  161.        
  162.  
  163.         static{
  164.  
  165.                 uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  166.  
  167.                 uriMatcher.addURI("cicero.org.provider.CiceroContentProvider", "settings", SETTINGS);
  168.  
  169.                 uriMatcher.addURI("cicero.org.provider.CiceroContentProvider", "settings/#", SETTINGS_ID);
  170.  
  171.         }
  172.  
  173.        
  174.  
  175.  
  176.  
  177.         @Override
  178.  
  179.         public String getType(Uri uri) {
  180.  
  181.                 switch(uriMatcher.match(uri)){
  182.  
  183.                 case SETTINGS:
  184.  
  185.                         return "vnd.android.cursor.dir/vnd.org.CiceroContentProvider";
  186.  
  187.                 case SETTINGS_ID:
  188.  
  189.                         return "vnd.android.cursor.item/vnd.org.CiceroContentProvider";
  190.  
  191.                 default:
  192.  
  193.                         throw new IllegalArgumentException("Unsupported URI: " + uri);
  194.  
  195.                 }
  196.  
  197.                
  198.  
  199.         }
  200.  
  201.  
  202.  
  203.        
  204.  
  205.  
  206.  
  207.         @Override
  208.  
  209.         public boolean onCreate() {
  210.  
  211.                 Context context = getContext();
  212.  
  213.                
  214.  
  215.                 settingsDatabaseHelper dbHelper;
  216.  
  217.                 dbHelper = new settingsDatabaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
  218.  
  219.                
  220.  
  221.                 SQLiteDatabase settingsDB = dbHelper.getWritableDatabase();
  222.  
  223.                 return (settingsDB == null) ? false : true;
  224.  
  225.         }
  226.  
  227.  
  228.  
  229.         @Override
  230.  
  231.         public Cursor query(Uri uri, String[] projection, String selection,
  232.  
  233.                         String[] selectionArgs, String sortOrder) {
  234.  
  235.                
  236.  
  237.                 SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
  238.  
  239.                
  240.  
  241.                 qBuilder.setTables(SETTINGS_TABLE);
  242.  
  243.                
  244.  
  245.                 switch(uriMatcher.match(uri)){
  246.  
  247.                
  248.  
  249.                 case SETTINGS_ID:
  250.  
  251.                         qBuilder.appendWhere(_ID + "=" + uri.getPathSegments().get(1));
  252.  
  253.                         break;
  254.  
  255.                 default:
  256.  
  257.                         break;
  258.  
  259.                
  260.  
  261.                 }
  262.  
  263.                
  264.  
  265.                 String orderBy;
  266.  
  267.                
  268.  
  269.                 if(TextUtils.isEmpty(sortOrder)){
  270.  
  271.                        
  272.  
  273.                         orderBy = VOIPUSERNAME;
  274.  
  275.                        
  276.  
  277.                 }
  278.  
  279.                 else{
  280.  
  281.                        
  282.  
  283.                         orderBy = sortOrder;
  284.  
  285.                        
  286.  
  287.                 }
  288.  
  289.                
  290.  
  291.                 Cursor c = qBuilder.query(settingsDB, projection, selection, selectionArgs, null, null, orderBy);
  292.  
  293.                
  294.  
  295.                 c.setNotificationUri(getContext().getContentResolver(), uri);
  296.  
  297.                
  298.  
  299.                 return c;
  300.  
  301.         }
  302.  
  303.  
  304.  
  305.         @Override
  306.  
  307.         public int update(Uri uri, ContentValues values, String selection,
  308.  
  309.                         String[] selectionArgs) {
  310.  
  311.                
  312.  
  313.                 int count;
  314.  
  315.                
  316.  
  317.                 switch(uriMatcher.match(uri)){
  318.  
  319.                
  320.  
  321.                 case SETTINGS:
  322.  
  323.                         count = settingsDB.update(SETTINGS_TABLE, values, selection, selectionArgs);
  324.  
  325.                         break;
  326.  
  327.                        
  328.  
  329.                 case SETTINGS_ID:
  330.  
  331.                         String segment = uri.getPathSegments().get(1);
  332.  
  333.                         count = settingsDB.update(SETTINGS_TABLE, values, _ID + "=" + segment + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
  334.  
  335.                         break;
  336.  
  337.                        
  338.  
  339.                 default:
  340.  
  341.                         throw new IllegalArgumentException("Unkonwn URI " + uri);
  342.  
  343.                 }
  344.  
  345.                 getContext().getContentResolver().notifyChange(uri, null);
  346.  
  347.                 return count;
  348.  
  349.         }
  350.  
  351.        
  352.  
  353.         @Override
  354.  
  355.         public int delete(Uri uri, String selection, String[] selectionArgs) {
  356.  
  357.                
  358.  
  359.                 int count;
  360.  
  361.                
  362.  
  363.                 switch(uriMatcher.match(uri)){
  364.  
  365.                
  366.  
  367.                 case SETTINGS:
  368.  
  369.                         count = settingsDB.delete(SETTINGS_TABLE, selection, selectionArgs);
  370.  
  371.                         break;
  372.  
  373.                        
  374.  
  375.                 case SETTINGS_ID:
  376.  
  377.                         String segment = uri.getPathSegments().get(1);
  378.  
  379.                         count = settingsDB.delete(SETTINGS_TABLE, _ID + "=" + segment + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')':""), selectionArgs);
  380.  
  381.                         break;
  382.  
  383.                
  384.  
  385.                 default:
  386.  
  387.                         throw new IllegalArgumentException("Unsupported URI: " + uri);
  388.  
  389.                 }
  390.  
  391.                 getContext().getContentResolver().notifyChange(uri, null);
  392.  
  393.                 return count;
  394.  
  395.         }
  396.  
  397.        
  398.  
  399.         @Override
  400.  
  401.         public Uri insert(Uri _uri, ContentValues _initialValues) {
  402.  
  403.                 long rowId = settingsDB.insert(SETTINGS_TABLE, "settings",_initialValues);
  404.  
  405.                
  406.  
  407.                 if(rowId > 0){
  408.  
  409.                        
  410.  
  411.                         Uri uri = ContentUris.withAppendedId(CONTENT_URI, rowId);
  412.  
  413.                         getContext().getContentResolver().notifyChange(uri, null);
  414.  
  415.                         return uri;
  416.  
  417.                 }
  418.  
  419.                 throw new SQLException("Failed to insert row into " + _uri);
  420.  
  421.  
  422.  
  423.         }
  424.  
  425. }
Parsed in 0.056 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Postby Draffodx » Mon Dec 21, 2009 5:17 pm

I think it has something to do with there being no data in my content provider or my content provider not being created?
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby Draffodx » Tue Dec 22, 2009 1:11 pm

For anyone that comes across this I had the xml manifest code outside the application tags giving me the no content provider info found error
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby regulatre » Thu Dec 31, 2009 5:24 pm

Thanks for posting your fix.

I'm starting down the path of a Content Provider now and reading this type of problem/solution is always helpful.
regulatre
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 03, 2009 1:33 am

Postby Draffodx » Thu Jan 07, 2010 4:18 pm

Have come across a new problem when trying to update a row in the content provider.

I can add no problem but when I go to update a single row I get the following error:

01-07 15:00:56.584: ERROR/AndroidRuntime(28190): java.lang.IllegalArgumentException: Unkonwn URI content://cicero.org.GetCallLog.CiceroContentProvider/1


The 1 is supposed to reference the row I want to update but it seems to be causing the problem.

My code is the same as in my first post.

But here is the update code used outside the Content Provider.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void updateSettings(int callId, Settings aNewSettings){
  2.  
  3.                
  4.  
  5.         ContentResolver cr = getContentResolver();
  6.  
  7.                 ContentValues values = new ContentValues();
  8.  
  9.            
  10.  
  11.         values.put(CiceroContentProvider.VOIPUSERNAME, aNewSettings.getVoipUserName());
  12.  
  13.         values.put(CiceroContentProvider.VOIPAUTHID, aNewSettings.getVoipAuthId());
  14.  
  15.         values.put(CiceroContentProvider.PASSWORD, aNewSettings.getPassword());
  16.  
  17.         values.put(CiceroContentProvider.VOIPDISPLAYNAME, aNewSettings.getVoipDisplayName());
  18.  
  19.         values.put(CiceroContentProvider.SIPPROXYSERVER, aNewSettings.getSipProxyServer());
  20.  
  21.         values.put(CiceroContentProvider.SIPREGISTRAR, aNewSettings.getSipRegistrar());
  22.  
  23.         values.put(CiceroContentProvider.SIPREALM, aNewSettings.getSipRealm());
  24.  
  25.         values.put(CiceroContentProvider.EXPIRESTIME, Integer.toString(aNewSettings.getExpiresTime()));
  26.  
  27.            
  28.  
  29.             Uri uri = ContentUris.withAppendedId(CiceroContentProvider.CONTENT_URI, callId);
  30.  
  31.             Log.d("URI", "URI Updated: " + uri);
  32.  
  33.             int rows = cr.update(uri, values, null, null);
  34.  
  35.            
  36.  
  37.             Log.d("DEBUG", "Rows Updated: " + rows);
  38.  
  39.         }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


With CallId being the 1 that is passed in.

I cant figure out what I'm doing wrong :(
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby regulatre » Thu Jan 07, 2010 4:26 pm

Check out the stack trace when it happens and find out which method is being called that triggers the message. or post the stack trace.
regulatre
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 03, 2009 1:33 am

Top

Postby Draffodx » Thu Jan 07, 2010 4:30 pm

01-07 15:00:56.573: ERROR/AndroidRuntime(28190): Uncaught handler: thread main exiting due to uncaught exception
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): java.lang.IllegalArgumentException: Unkonwn URI content://cicero.org.GetCallLog.CiceroContentProvider/1
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): at cicero.org.GetCallLog.CiceroContentProvider.update(CiceroContentProvider.java:128)
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): at android.content.ContentProvider$Transport.update(ContentProvider.java:156)
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): at android.content.ContentResolver.update(ContentResolver.java:554)
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): at cicero.org.GetCallLog.GetCallLog.updateSettings(GetCallLog.java:277)
01-07 15:00:56.584: ERROR/AndroidRuntime(28190): at android.view.View.performClick(View.java:2179)


It gets stuck at this peice of code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int rows = cr.update(uri, values, null, null);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Which in turn calls this piece of code in the content provider

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.         public int update(Uri uri, ContentValues values, String selection,
  4.  
  5.                         String[] selectionArgs) {
  6.  
  7.                
  8.  
  9.                 int count = 0;
  10.  
  11.                 Log.d("UPDATE CONTENT", "UPDATE COUNT = " + uriMatcher.match(uri));
  12.  
  13.                 switch(uriMatcher.match(uri)){
  14.  
  15.                
  16.  
  17.                 case SETTINGS:
  18.  
  19.                         count = settingsDB.update(SETTINGS_TABLE, values, selection, selectionArgs);
  20.  
  21.                         break;
  22.  
  23.                        
  24.  
  25.                 case SETTINGS_ID:
  26.  
  27.                         String segment = uri.getPathSegments().get(1);
  28.  
  29.                         count = settingsDB.update(SETTINGS_TABLE, values, _ID + "=" + segment + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
  30.  
  31.                         break;
  32.  
  33.                        
  34.  
  35.                 default:
  36.  
  37.                         throw new IllegalArgumentException("Unkonwn URI " + uri);
  38.  
  39.                 }
  40.  
  41.                 getContext().getContentResolver().notifyChange(uri, null);
  42.  
  43.                 return count;
  44.  
  45.         }
  46.  
  47.        
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Log.d("UPDATE CONTENT", "UPDATE COUNT = " + uriMatcher.match(uri)); prints out a -1 which means it gets switched to default and then the IllegalArgumentException is thrown

It should be giving 2 so that it switchs to the SETTINGS_ID case
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby regulatre » Thu Jan 07, 2010 4:36 pm

Something looks fishy in the URI:

01-07 15:00:56.584: ERROR/AndroidRuntime(28190): java.lang.IllegalArgumentException: Unkonwn URI content://cicero.org.GetCallLog.CiceroContentProvider/1


Shouldn't there be something else before the 1, like the table name or data type? As it is printed above it looks

In other words, it looks like you're doing
content://com.blah/1

instead of
content://com.blah/getnames/1

??
regulatre
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 03, 2009 1:33 am

Postby Draffodx » Thu Jan 07, 2010 4:45 pm

Thanks,

Changing the CONTENT_URI to content://cicero.org.GetCallLog.CiceroC ... r/settings appears to have worked, although this is not how it was done in any of the tutorials I followed so there may be a flaw in my code somewhere still.

But for now its working, thanks again :D
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby regulatre » Thu Jan 07, 2010 4:53 pm

Yeah I'm not sure if a switch is going to be your friend or not in this case.

I'm implementing mine something like this:

Code: Select all
if (uri.tostring().contains("com.blah/stuff"))  {
    handle stuff

    if (there's a record specified such as stuff/1)
        parse out the record number
        do special stuff with that record.
}

regulatre
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 03, 2009 1:33 am

Postby soch » Mon Jan 18, 2010 9:54 am

Thanks for posting valuable information in regards to manifest file. My <provider> tag was also outside teh application tab and I had spent all day finding the problem. Finally your suggestion fixed it.
soch
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 07, 2010 11:46 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests