【问题标题】:Failed to find provider info for com.courses.applicationcontentprovider.provider找不到 com.courses.applicationcontentprovider.provider 的提供者信息
【发布时间】:2021-09-02 03:04:05
【问题描述】:

#我的应用程序一直在工作,直到我尝试将消息保存在数据库中,请参见此处的图像: #[App_Working][1]

#[1]:https://i.stack.imgur.com/G26MS.jpg

#我试图找到 content://com.courses.applicationcontentprovider.provider/notes 文件,但我是发展中国家的新手,没有找到

#谁能告诉我如何解决这个问题?

#我也检查了一些类似的问题,但这不起作用。

#这是我的 AndroidManiFest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.ApplicationContentProvider.">
    <provider
        android:name=".database.NotesProvider"
        android:authorities="com.example.applicationcontentprovider.provider"
        android:enabled="true"
        android:exported="true" />

    <activity
        android:name=".database.MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

#还有logcat中指向NotesDetailFragments.kt

Process: com.example.contentprovider, PID: 787
java.lang.IllegalArgumentException: Unknown URL content://com.courses.applicationcontentprovider.provider/notes
    at android.content.ContentResolver.insert(ContentResolver.java:2145)
    at android.content.ContentResolver.insert(ContentResolver.java:2111)
    at com.example.contentprovider.database.NotesDetailFragments.onClick(NotesDetailFragments.kt:78)
    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:174)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

#谢谢

【问题讨论】:

  • 请将所有信息放入本站。如果另一个倒下,没有人会理解你的问题。

标签: java android-studio kotlin


【解决方案1】:

类 NotesDetailFragments: DialogFragment(), DialogInterface.OnClickListener {

private lateinit var noteEdiTitle: EditText
private lateinit var noteEditDescription: EditText
private var id: Long = 0

companion object {
    private const val  EXTRA_ID = "id"
    fun newInstance(id: Long): NotesDetailFragments {
        val bundle = Bundle()
        bundle.putLong(EXTRA_ID, id)

        val notesFragment = NotesDetailFragments()
        notesFragment.arguments = bundle
        return notesFragment
    }

}


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val view: View? = activity?.layoutInflater?.inflate(R.layout.note_detail, null)

    noteEdiTitle = view?.findViewById(R.id.note_edt_title) as EditText
    noteEditDescription = view.findViewById(R.id.note_edt_description) as EditText

    var newNote = true
    if (arguments != null && arguments?.getLong(EXTRA_ID) != 0L){
        id = arguments?.getLong(EXTRA_ID) as Long
        val uri = Uri.withAppendedPath(URI_NOTES, id.toString())
        val cursor =
            activity?.contentResolver?.query(uri, null, null, null, null)

        if (cursor?.moveToNext() as Boolean ) {
            newNote = false
            noteEdiTitle.setText(cursor.getString(cursor.getColumnIndex(TITTLE_NOTES)))
            noteEditDescription.setText(cursor.getString(cursor.getColumnIndex(DESCRIPTION_NOTES)))
        }
        cursor.close()
    }


    return AlertDialog.Builder(activity as Activity)
        .setTitle(if (newNote) "Nova mensagem" else "Editar Mensagem")
        .setView(view)
        .setPositiveButton("Salvar", this)
        .setNegativeButton("Cancelar", this)
        .create()
}

override fun onClick(dialog: DialogInterface?, which: Int) {
    val values = ContentValues()
    values.put(TITTLE_NOTES, noteEdiTitle.text.toString())
    values.put(DESCRIPTION_NOTES, noteEditDescription.text.toString())

    if(id != 0L){
        val uri = Uri.withAppendedPath(URI_NOTES, id.toString())
        context?.contentResolver?.update(uri, values, null, null)

    }else {
        context?.contentResolver?.insert(URI_NOTES, values)
    }

}

【讨论】:

  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-31
  • 1970-01-01
  • 2012-09-22
相关资源
最近更新 更多