Java E/ActivityThread:未能找到提供程序信息(致命错误)

Java E/ActivityThread:未能找到提供程序信息(致命错误),java,android,google-maps,Java,Android,Google Maps,我得到了不同的错误,如: java.lang.RuntimeException: An error occurred while executing doInBackground() /ActivityThread: Failed to find provider info for (my package name here) E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Caused by: java.lang.IllegalArgume

我得到了不同的错误,如:

java.lang.RuntimeException: An error occurred while executing doInBackground()

/ActivityThread: Failed to find provider info for (my package name here)
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

 Caused by: java.lang.IllegalArgumentException: Unknown URL content

Any ideas on what is wrong with my code?

I think that the error lies somewhere in the provider/uri creation

I took my package name out of the code for privacy reasons, I replaced it with ""

Thank you so much! :)
你好,

I am getting different errors saying:

java.lang.RuntimeException: An error occurred while executing doInBackground()

/ActivityThread: Failed to find provider info for (my package name here)
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

 Caused by: java.lang.IllegalArgumentException: Unknown URL content

Any ideas on what is wrong with my code?

I think that the error lies somewhere in the provider/uri creation

I took my package name out of the code for privacy reasons, I replaced it with ""

Thank you so much! :)





**Maps Activity.Java**

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;

import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback , LoaderManager.LoaderCallbacks {

    private final LatLng LOCATION_UNIV = new LatLng(37.335371, -121.881050);
    private final LatLng LOCATION_CS = new LatLng(37.333714, -121.881860);
    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


    }

    @Override
    public void onMapReady(GoogleMap googleMapR) {
        googleMap = googleMapR;
        googleMap.addMarker(new MarkerOptions().position(LOCATION_CS).title("Find Me Here!"));

        googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

            @Override
            public void onMapClick(LatLng point) {

// Drawing marker on the map
                drawMarker(point);

// Creating an instance of ContentValues
                ContentValues contentValues = new ContentValues();

// Setting latitude in ContentValues
                contentValues.put(LocationsDB.FIELD_LAT, point.latitude);

// Setting longitude in ContentValues
                contentValues.put(LocationsDB.FIELD_LNG, point.longitude);

// Setting zoom in ContentValues
                contentValues.put(LocationsDB.FIELD_ZOOM, googleMap.getCameraPosition().zoom);

// Creating an instance of LocationInsertTask
                LocationInsertTask insertTask = new LocationInsertTask();

// Storing the latitude, longitude and zoom level to SQLite database
                insertTask.execute(contentValues);

                Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();

            }
        });
    }





    private class LocationInsertTask extends AsyncTask<ContentValues, Void, Void> {
        @Override
        protected Void doInBackground(ContentValues... contentValues) {

/** Setting up values to insert the clicked location into SQLite database */
            getContentResolver().insert(LocationsContentProvider.CONTENT_URI, contentValues[0]);
            return null;
        }
    }

    private void drawMarker(LatLng point){
// Creating an instance of MarkerOptions
        MarkerOptions markerOptions = new MarkerOptions();

// Setting latitude and longitude for the marker
        markerOptions.position(point);

// Adding marker on the Google Map
        googleMap.addMarker(markerOptions);
    }

    private class LocationDeleteTask extends AsyncTask<Void, Void, Void>{
        @Override
        protected Void doInBackground(Void... params) {

/** Deleting all the locations stored in SQLite database */
            getContentResolver().delete(LocationsContentProvider.CONTENT_URI, null, null);
            return null;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public Loader onCreateLoader(int arg0,
                                 Bundle arg1) {

// Uri to the content provider LocationsContentProvider
        Uri uri = LocationsContentProvider.CONTENT_URI;

// Fetches all the rows from locations table
        return new CursorLoader(this, uri, null, null, null, null);

    }

    @Override
    public void onLoadFinished(@NonNull Loader loader, Object data) {

        Cursor cursor = (Cursor) data;
        this.onLoadFinished1(loader, cursor);
    }

    public void onLoadFinished1( Loader arg0, Cursor arg1) {

        int locationCount = 0;
        double lat=0;
        double lng=0;
        float zoom=0;

// Number of locations available in the SQLite database table
        locationCount = arg1.getCount();

// Move the current record pointer to the first row of the table
        arg1.moveToFirst();

        for(int i=0;i<locationCount;i++){

// Get the latitude
            lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));

// Get the longitude
            lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));

// Get the zoom level
            zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));

// Creating an instance of LatLng to plot the location in Google Maps
            LatLng location = new LatLng(lat, lng);

// Drawing the marker in the Google Maps
            drawMarker(location);

// Traverse the pointer to the next row
            arg1.moveToNext();
        }

        if(locationCount>0){
// Moving CameraPosition to last clicked position
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));

// Setting the zoom level in the map on last position is clicked
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));

        }
    }




    public void onLoaderReset(Loader arg0) {
// TODO Auto-generated method stub
    }



    public void onClick_CS(View v) {
        googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_CS, 18);
        googleMap.animateCamera(update);
    }

    public void onClick_Univ(View v) {
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_UNIV, 14);
        googleMap.animateCamera(update);
    }

    public void onClick_City(View v) {
        googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_UNIV, 10);
        googleMap.animateCamera(update);
    }


}


LocationsDB.java

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class LocationsDB extends SQLiteOpenHelper{

    /** Database name */
    private static String DBNAME = "locationmarkersqlite";

    /** Version number of the database */
    private static int VERSION = 1;

    /** Field 1 of the table locations, which is the primary key */
    public static final String FIELD_ROW_ID = "_id";

    /** Field 2 of the table locations, stores the latitude */
    public static final String FIELD_LAT = "lat";

    /** Field 3 of the table locations, stores the longitude*/
    public static final String FIELD_LNG = "lng";

    /** Field 4 of the table locations, stores the zoom level of map*/
    public static final String FIELD_ZOOM = "zom";

    /** A constant, stores the the table name */
    private static final String DATABASE_TABLE = "locations";

    /** An instance variable for SQLiteDatabase */
    private SQLiteDatabase mDB;

    /** Constructor */
    public LocationsDB(Context context) {
        super(context, DBNAME, null, VERSION);
        this.mDB = getWritableDatabase();
    }

    /** This is a callback method, invoked when the method getReadableDatabase() / getWritableDatabase() is called
     * provided the database does not exists
     * */
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table " + DATABASE_TABLE + " ( " +
                FIELD_ROW_ID + " integer primary key autoincrement , " +
                FIELD_LNG + " double , " +
                FIELD_LAT + " double , " +
                FIELD_ZOOM + " text " +
                " ) ";

        db.execSQL(sql);
    }

    /** Inserts a new location to the table locations */
    public long insert(ContentValues contentValues){
        long rowID = mDB.insert(DATABASE_TABLE, null, contentValues);
        return rowID;

    }

    /** Deletes all locations from the table */
    public int del(){
        int cnt = mDB.delete(DATABASE_TABLE, null , null);
        return cnt;
    }

    /** Returns all the locations from the table */
    public Cursor getAllLocations(){
        return mDB.query(DATABASE_TABLE, new String[] { FIELD_ROW_ID, FIELD_LAT , FIELD_LNG, FIELD_ZOOM } , null, null, null, null, null);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}

**LocationsContentProvider.java**

import java.sql.SQLException;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

/** A custom Content Provider to do the database operations */
public class LocationsContentProvider extends ContentProvider{

    public static final String PROVIDER_NAME = "";

    /** A uri to do operations on locations table. A content provider is identified by its uri */
    public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/locations" );

    /** Constant to identify the requested operation */
    private static final int LOCATIONS = 1;

    private static final UriMatcher uriMatcher ;

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

    /** This content provider does the database operations by this object */
    LocationsDB mLocationsDB;

    /** A callback method which is invoked when the content provider is starting up */
    @Override
    public boolean onCreate() {
        mLocationsDB = new LocationsDB(getContext());
        return true;
    }

    /** A callback method which is invoked when insert operation is requested on this content provider */
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        long rowID = mLocationsDB.insert(values);
        Uri _uri=null;
        if(rowID>0){
            _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
        }else {
            try {
                throw new SQLException("Failed to insert : " + uri);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return _uri;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
// TODO Auto-generated method stub
        return 0;
    }

    /** A callback method which is invoked when delete operation is requested on this content provider */
    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        int cnt = 0;
        cnt = mLocationsDB.del();
        return cnt;
    }

    /** A callback method which is invoked by default content uri */
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

        if(uriMatcher.match(uri)==LOCATIONS){
            return mLocationsDB.getAllLocations();
        }
        return null;
    }

    @Override
    public String getType(Uri uri) {
        return null;
    }
}

**Android Manifest (partial)**

<permission
        android:name="edu."".android.mymaps2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <uses-permission android:name="edu."".android.example2.permission.MAPS_RECEIVE" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-feature android:name="android.hardware.camera" android:required="true"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
        Google Maps Android API v2, but are recommended. -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        >
        <uses-library android:name="com.google.android.maps" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name="edu."".android.mymaps2.MapsActivity"
            android:label="@string/title_activity_maps">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
我收到了不同的错误,如:
java.lang.RuntimeException:执行doInBackground()时出错
/ActivityThread:未能找到的提供程序信息(此处是我的包名)
E/AndroidRuntime:致命异常:AsyncTask#1
原因:java.lang.IllegalArgumentException:未知URL内容
我的代码有什么问题吗?
我认为错误在provider/uri创建中的某个地方
出于隐私原因,我从代码中删除了我的包名,并将其替换为“”
非常感谢!:)
**Maps Activity.Java**
导入android.content.ContentValues;
导入android.database.Cursor;
导入android.net.Uri;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.view;
导入android.widget.Toast;
导入androidx.annotation.NonNull;
导入androidx.fragment.app.FragmentActivity;
导入androidx.loader.app.LoaderManager;
导入androidx.loader.content.CursorLoader;
导入androidx.loader.content.loader;
导入com.google.android.gms.maps.*;
导入com.google.android.gms.maps.model.*;
公共类MapsActivity扩展了FragmentActivity在MapreadyCallback、LoaderManager.LoaderCallbacks上的实现{
私人最终车床位置大学=新车床(37.335371,-121.881050);
私人最终车床位置=新车床(37.333714,-121.881860);
私人谷歌地图谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
}
@凌驾
mapready上的公共无效(谷歌地图谷歌地图){
谷歌地图=谷歌地图;
addMarker(新的MarkerOptions().position(LOCATION_CS).title(“在这里找到我!”);
setOnMapClickListener(新的googleMap.OnMapClickListener(){
@凌驾
公共空区(停车点){
//在地图上画标记
绘图标记(点);
//创建ContentValues的实例
ContentValues ContentValues=新ContentValues();
//设置内容值中的纬度
contentValues.put(位置、字段纬度、点纬度);
//在ContentValue中设置经度
contentValues.put(位置、地点、经度);
//设置缩放内容值
contentValues.put(LocationsDB.FIELD\u ZOOM,googleMap.getCameraPosition().ZOOM);
//创建LocationInsertTask的实例
LocationInsertTask insertTask=新LocationInsertTask();
//将纬度、经度和缩放级别存储到SQLite数据库
insertTask.execute(contentValues);
Toast.makeText(getBaseContext(),“将标记添加到映射中”,Toast.LENGTH_SHORT.show();
}
});
}
私有类LocationInsertTask扩展了AsyncTask{
@凌驾
受保护的Void doInBackground(ContentValues…ContentValues){
/**设置值以将单击的位置插入SQLite数据库*/
getContentResolver().insert(LocationsContentProvider.CONTENT_URI,contentValues[0]);
返回null;
}
}
专用空位标记器(LatLng点){
//创建MarkerOptions的实例
MarkerOptions MarkerOptions=新MarkerOptions();
//设置标记的纬度和经度
标记选项。位置(点);
//在谷歌地图上添加标记
googleMap.addMarker(markerOptions);
}
私有类LocationDeleteTask扩展了AsyncTask{
@凌驾
受保护的Void doInBackground(Void…参数){
/**删除SQLite数据库中存储的所有位置*/
getContentResolver().delete(LocationsContentProvider.CONTENT\u URI,null,null);
返回null;
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
公共加载器onCreateLoader(int arg0,
捆绑包arg1){
//内容提供程序位置ContentProvider的Uri
Uri=位置ContentProvider.CONTENT\u Uri;
//从位置表中获取所有行
返回新的游标装入器(this,uri,null,null,null,null);
}
@凌驾
public void onLoadFinished(@NonNull加载程序,对象数据){
游标=(游标)数据;
此.onLoadFinished1(加载器,光标);
}
public void onLoadFinished1(加载器arg0,光标arg1){
int locationCount=0;
双lat=0;
双液化天然气=0;
浮动缩放=0;
//SQLite数据库表中可用的位置数
locationCount=arg1.getCount();
//将当前记录指针移动到表的第一行
arg1.moveToFirst();
对于(int i=0;i0){
//将CameraPosition移动到上次单击的位置
googleMap.moveCamera(CameraUpdateFactory.newLatLng(newLatLng,lat,lng));
//单击“在地图上最后一个位置设置缩放级别”
googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
}
}
公共void onLoaderReset(加载程序arg0){
//TODO自动生成的方法存根
}
点击图标后的公共空白(视图五){
googleMap.setMapType(googleMap.MAP\u TYPE\u地形);
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(位置18);
googleMap.animateCamera(更新);
}
伦敦大学公共空间(视图五){
googleMap.setMapType(googleMap.MAP\u TYPE\u NORMAL);
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(地点大学,14);
谷歌地图。动画美人鱼(upda)