简体   繁体   中英

Error: java.lang.ClassNotFoundException

It keeps saying class not found but i seem to see no errors in any Java class. Is it because of something wrong in the manifest file or Java Build paths? Please help. And why is asking a question so hard. It keeps saying give more details and stuff.

This is the logcat

04-21 04:41:21.709: E/AndroidRuntime(1179): FATAL EXCEPTION: main

04-21 04:41:21.709: **E/AndroidRuntime(1179): java.lang.RuntimeException: Unable to get provider com.work.pets.data.PetProvider: java.lang.ClassNotFoundException: com.work.pets.data.PetProvider**

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.installProvider(ActivityThread.java:4563)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.access$1300(ActivityThread.java:130)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.os.Handler.dispatchMessage(Handler.java:99)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.os.Looper.loop(Looper.java:137)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.main(ActivityThread.java:4745)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at java.lang.reflect.Method.invokeNative(Native Method)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at java.lang.reflect.Method.invoke(Method.java:511)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at dalvik.system.NativeStart.main(Native Method)

04-21 04:41:21.709: E/AndroidRuntime(1179): Caused by: java.lang.ClassNotFoundException: com.work.pets.data.PetProvider

04-21 04:41:21.709: E/AndroidRuntime(1179):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

04-21 04:41:21.709: E/AndroidRuntime(1179):     at android.app.ActivityThread.installProvider(ActivityThread.java:4548)

04-21 04:41:21.709: E/AndroidRuntime(1179):     ... 12 more

04-21 04:41:21.713: W/ActivityManager(337):   Force finishing activity com.work.pets/.Main

This is the complete code of Provider Class

package data;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;
import data.PetContract.PetEntry;

public class PetProvider extends ContentProvider{

private static final int PETS=100;

private static final int PET_ID=101;

public static final String LOG_TAG = PetProvider.class.getSimpleName();

private static final UriMatcher sUriMatcher=new UriMatcher(UriMatcher.NO_MATCH);

static{

sUriMatcher.addURI(PetContract.CONTENT_AUTHORITY, PetContract.PATH_PETS, PETS);

sUriMatcher.addURI(PetContract.CONTENT_AUTHORITY, PetContract.PATH_PETS + "/#", PET_ID);
}

private PetDbHelper nDbHelper;

@Override
public boolean onCreate() {

nDbHelper = new PetDbHelper(getContext());

return true;

}

@Override

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

SQLiteDatabase database = nDbHelper.getReadableDatabase();

Cursor cursor;

int match = sUriMatcher.match(uri);

switch(match){

case PETS:cursor = database.query(PetEntry.TABLE_NAME, projection,
selection, selectionArgs, null, null, sortOrder);

break;

case PET_ID:

selection = PetEntry._ID + "=?";

selectionArgs = new String[]{String.valueOf(ContentUris.parseId(uri)) };

cursor = database.query(PetEntry.TABLE_NAME, projection, selection,
selectionArgs, null, null, sortOrder);

break;

default:

throw new IllegalArgumentException("Cannot query unknown URI" + uri);

}

return cursor;

}
@Override

public String getType(Uri uri) {

return null;

}
@Override

public Uri insert(Uri uri, ContentValues contentvalues) {

final int match = sUriMatcher.match(uri);

switch(match){

case PETS:

return insertPet(uri,contentvalues);

default:

throw new IllegalArgumentException("Insertion is not supported for " + uri);

}   

}
private Uri insertPet(Uri uri,ContentValues values){

SQLiteDatabase database = nDbHelper.getWritableDatabase();

long id = database.insert(PetEntry.TABLE_NAME, null, values);

if (id == -1) {

Log.e(LOG_TAG, "Failed to insert row for " + uri);

return null;

}

return ContentUris.withAppendedId(uri, id);

}

@Override

public int delete(Uri uri, String selection, String[] selectionArgs) {

return 0;

}

@Override

public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

return 0;

}

}

This is the Provider part of Manifest File:-

<provider android:name=".data.PetProvider"

android:authorities="com.work.pets"

android:exported="false"/>

Your package is wrong. The code doesn't lie... This doesn't exist.

com.work.pets.data.PetProvider

data.PetProvider does...

Fix package data; to use your application's package

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM