我搜索了这个问题,但没有找到任何与我的问题相关的答案。我希望以前有人能解决这个问题并且可以帮助我( - :。
Uri soundUri = loadSoundFromLocal(context, "sound.wav");
private Uri loadSoundFromLocal(Context context, String sound) {
try {
// Get resource id.
boolean isGmeResource = true;
int soundResource = UtilsResources.getResId(sound, R.raw.class);
if (soundResource == -1 || soundResource == 0) {
soundResource = UtilsResources.getIdentifier(context, sound, "raw");
if (soundResource != -1 && soundResource != 0) {
isGmeResource = false;
}
}
// Create the uri string for the sound file.
if (soundResource == -1 || soundResource == 0) {
return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
} else {
return UtilsResources.getUriFromResId(context, soundResource, isGmeResource);
}
} catch (Exception e) {
return null;
}
}
public static int getResId(String resourceName, Class<?> c) {
if (TextUtils.isEmpty(resourceName)) { return -1; }
if (c == null) { return -1; }
try {
Field field = c.getField(resourceName);
if (field == null) {
return -1;
}
return field.getInt(null);
} catch (Exception e) {
return -1;
}
}
public static int getIdentifier(Context context, String name, String defType) {
String appPackageName = UtilsData.getAppPackageName(context);
if (TextUtils.isEmpty(appPackageName)) {
return -1;
}
if (context.getPackageManager() == null) { return -1; }
if (TextUtils.isEmpty(name)) { return -1; }
if (TextUtils.isEmpty(defType)) { return -1; }
try {
Resources resources = context.getPackageManager().getResourcesForApplication(appPackageName);
if (resources == null) {
return -1;
}
return resources.getIdentifier(name, defType, appPackageName);
} catch (NameNotFoundException e) {
// Should never happen
UtilsLogger.e(LOG_TAG, (e != null)? e.getMessage() : "Could not get package name");
return -1;
} catch (Exception e) {
UtilsLogger.e(LOG_TAG, (e != null)? e.getMessage() : "Could not get identifier version code");
return -1;
}
}
EXCEPTION :
Process: com.growmobile.engagement.sample, PID: 20883
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/growmobile/engagement/R$raw;
at com.growmobile.engagement.ModelPushMessage.loadSoundFromLocal(ModelPushMessage.java:451)
at com.growmobile.engagement.ModelPushMessage.parseMessageData(ModelPushMessage.java:375)
at com.growmobile.engagement.ModelPushMessage.<init>(ModelPushMessage.java:174)
at com.growmobile.engagement.ManagerNotification.buildPushMessageObjectAndSaveItToDB(ManagerNotification.java:139)
at com.growmobile.engagement.ManagerNotification.buildGMENotificationObject(ManagerNotification.java:108)
at com.growmobile.engagement.ManagerNotification.initializeNotification(ManagerNotification.java:77)
at com.growmobile.engagement.GMEGcmListenerService.executePushAction(GMEGcmListenerService.java:152)
at com.growmobile.engagement.GMEGcmListenerService.handleMessage(GMEGcmListenerService.java:118)
at com.growmobile.engagement.GMEGcmListenerService.onMessageReceived(GMEGcmListenerService.java:79)
at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.growmobile.engagement.R$raw" on path: DexPathList[[zip file "/data/app/com.growmobile.engagement.sample-1/base.apk"],nativeLibraryDirectories=[/data/app/com.growmobile.engagement.sample-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.growmobile.engagement.ModelPushMessage.loadSoundFromLocal(ModelPushMessage.java:451)
at com.growmobile.engagement.ModelPushMessage.parseMessageData(ModelPushMessage.java:375)
at com.growmobile.engagement.ModelPushMessage.<init>(ModelPushMessage.java:174)
at com.growmobile.engagement.ManagerNotification.buildPushMessageObjectAndSaveItToDB(ManagerNotification.java:139)
at com.growmobile.engagement.ManagerNotification.buildGMENotificationObject(ManagerNotification.java:108)
at com.growmobile.engagement.ManagerNotification.initializeNotification(ManagerNotification.java:77)
at com.growmobile.engagement.GMEGcmListenerService.executePushAction(GMEGcmListenerService.java:152)
at com.growmobile.engagement.GMEGcmListenerService.handleMessage(GMEGcmListenerService.java:118)
at com.growmobile.engagement.GMEGcmListenerService.onMessageReceived(GMEGcmListenerService.java:79)
at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: com.growmobile.engagement.R$raw
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 18 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
感谢您提前获得任何人的帮助 希望我能尽快得到答案( - :