错误:java.lang.ClassNotFoundException

时间:2017-04-21 05:38:09

标签: java android

它一直说类没找到,但我似乎没有看到任何Java类中的错误。是因为清单文件或Java Build路径中有什么问题吗?请帮忙。为什么这么难问一个问题。它一直在说提供更多细节和内容。

这是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

这是提供者类的完整代码

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;

}

}

这是清单文件的提供者部分: -

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

android:authorities="com.work.pets"

android:exported="false"/>

1 个答案:

答案 0 :(得分:0)

你的包裹错了。代码并不存在...这不存在。

com.work.pets.data.PetProvider

data.PetProvider确实......

修复package data;以使用您的应用程序包