android - 如何在android studio中修复 "Unknown URL content://com.new.newapp.locations/locations"

标签 android

这是我遇到的错误:

Caused by: java.lang.IllegalArgumentException: Unknown URL  content://com.new.newapp.locations/locations
        at android.content.ContentResolver.insert(ContentResolver.java:1213)
        at com.new.newapp.activity.FragmentGoogleMap$LocationInsertTask.doInBackground(FragmentGoogleMap.java:364)
        at com.new.newapp.activity.FragmentGoogleMap$LocationInsertTask.doInBackground(FragmentGoogleMap.java:360)

我研究了这个问题并发现了这些类似的问题: Link1 Link2 Link3

这些都没有帮助。最让我困扰的是,当我使用 eclipse 时,我没有遇到这个问题,但自从在 Android Studio 上工作后,我似乎无法让它工作。

在我的 LocationsContentProvider 类中:

package com.new.newapp.activity;

public class LocationsContentProvider extends ContentProvider{

public static final String PROVIDER_NAME ="com.new.newapp.activtiy.locations";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/locations" );
private static final int LOCATIONS = 1;
private static final UriMatcher uriMatcher ;

static {
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    uriMatcher.addURI(PROVIDER_NAME, "locations", LOCATIONS);
}

LocationsDB mLocationsDB;

在我的 list 中我有这个:

</activity>

    <provider
        android:name="com.new.newapp.activity.LocationsContentProvider"
        android:authorities="locations"
        android:exported="false" />

</application>

我试过 android:authorities="com.new.newapp.activity.locations" 我也试过 android:name=".LocationsContentProvider" 也搬家了

有人可以帮忙吗?

最佳答案

您的问题在于提供商名称。

<provider
        android:name="com.new.newapp.activity.LocationsContentProvider"
        android:authorities="locations"
        android:exported="false" />

public static final String PROVIDER_NAME ="com.new.newapp.activtiy.locations";

应该是

public static final String PROVIDER_NAME ="com.new.newapp.activity.LocationsContentProvider";

关于android - 如何在android studio中修复 "Unknown URL content://com.new.newapp.locations/locations",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32023122/

相关文章:

java - 绘图表面、unlockCanvasAndPost 和 IllegalArgumentException

android - 从我的应用程序启动 Play 商店应用程序后,是否可以自动打开 Play 商店应用程序的评级对话框?

java - 无法实例化 Activity (Android)

java - android webviewclient 在 UI 线程问题上运行

android - android NullPointerException 在 updateLocaleListFromAppContext 中崩溃

Android 日期选择器样式

android - getActivity null 异常警告?

java - 如何找到 assetManager.openFd() 的正确文件路径?

android - 如何将 android sqlite 表同步到远程数据库服务器上的表?

Android - ViewPager2 在调用 Diffutil.dispatchUpdatesTo 时将适配器位置重置为 0