Declaring Content Provider

旧街凉风 提交于 2019-12-04 06:52:50

Provider needs to be in the application tag.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tyczj.bowling"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity android:name="Tabs">
            <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
        </activity>

        <activity android:name="BowlersList"></activity>
    <provider android:name="com.tyczj.bowling.BowlersDB"
        android:authorities="com.tyczj.bowling.bowlersdb">
    </provider>
    </application>



</manifest>
Protonflux

You should not call db = DBHelper.getWritableDatabase(); in the ContentProvider onCreate. This is for the reason given in SQLiteOpenHelper documentation for getReadableDatabase and getWritableDatabase:

Like getWritableDatabase, this method may take a long time to return, so you should not call it from the application main thread, including from ContentProvider.onCreate().

Instead hold a reference to the SQLiteOpenHelper instance and call getWritableDatabase/getReadableDatabase as appropriate in the query/insert/delete/update methods which are called asynchronously if you are using Loaders.

Sorry this is not targeted directly at the question, but it is something I've seen all over the place in code samples.

you have got this error because you define your Provider outside of Application tag. so please define your provider inside application.

<application
       ........

    <provider 
        android:name="com.tyczj.bowling.BowlersDB"
        android:authorities="com.tyczj.bowling.bowlersdb">
    </provider>
    </application>

This is a good example of why to use the Android Manifest editor in Eclipse. It puts such items/components in their syntactically correct location so one doesn't need to worry about this question. Another way of looking at it: consider using the Manifest editor in the beginning (& occassionally throughout) just to confirm the correctness of your manifest.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!