Reputation: 1084
I am using parse for push notification i am getting following error
java.lang.NoClassDefFoundError: notifications.ParseUtils$1
at notifications.ParseUtils.registerParse(ParseUtils.java:33)
at com.techieweb.solutions.pickeronline.MyApplication.onCreate(MyApplication.java:20)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1017)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4590)
at android.app.ActivityThread.access$1400(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
I am using this for reference http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/
This is my ParseUtils.java class
public class ParseUtils {
private static String TAG = ParseUtils.class.getSimpleName();
public static void verifyParseConfiguration(Context context) {
if (TextUtils.isEmpty(AppConfig.PARSE_APPLICATION_ID) || TextUtils.isEmpty(AppConfig.PARSE_CLIENT_KEY)) {
Toast.makeText(context, "Please configure your Parse Application ID and Client Key in AppConfig.java", Toast.LENGTH_LONG).show();
((Activity) context).finish();
}
}
public static void registerParse(Context context) {
// initializing parse library
Parse.initialize(context, AppConfig.PARSE_APPLICATION_ID, AppConfig.PARSE_CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
//Shows error heree
ParsePush.subscribeInBackground(AppConfig.PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e(TAG, "Successfully subscribed to Parse!");
}
});
}
public static void subscribeWithEmail(String email) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("email", email);
installation.saveInBackground();
Log.e(TAG, "Subscribed with email: " + email);
}
}
and this is MyApplication
public class MyApplication extends Application {
private static MyApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
// register with parse
ParseUtils.registerParse(this);
}
public static synchronized MyApplication getInstance() {
return mInstance;
}
}
This is NotificationUtils class
public class NotificationUtils {
private String TAG = NotificationUtils.class.getSimpleName();
private Context mContext;
public NotificationUtils() {
}
public NotificationUtils(Context mContext) {
this.mContext = mContext;
}
public void showNotificationMessage(String title, String message, Intent intent) {
// Check for empty push message
if (TextUtils.isEmpty(message))
return;
if (isAppIsInBackground(mContext)) {
// notification icon
int icon = R.mipmap.ic_launcher;
int smallIcon = R.drawable.ic_push;
int mNotificationId = AppConfig.NOTIFICATION_ID;
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mContext,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
mContext);
Notification notification = mBuilder.setSmallIcon(smallIcon).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setStyle(inboxStyle)
.setContentIntent(resultPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.build();
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, notification);
} else {
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(intent);
}
}
/**
* Method checks if the app is in background or not
*
* @param context
* @return
*/
public static boolean isAppIsInBackground(Context context) {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
isInBackground = false;
}
}
}
}
} else {
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equals(context.getPackageName())) {
isInBackground = false;
}
}
return isInBackground;
}
}
Please help me.
Upvotes: 3
Views: 192
Reputation: 1084
Solved the error by removing
ParsePush.subscribeInBackground(AppConfig.PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e(TAG, "Successfully subscribed to Parse!");
}
});
and using only
ParseInstallation.getCurrentInstallation().saveInBackground();
Upvotes: 4
Reputation: 75788
NoClassDefFoundError is thrown when the definition of class in not available during runtime. This error also indicates that the definition of the class was found during the compilation of the application, but it is not available in the application’s classpath during runtime.
java.lang.NoClassDefFoundError: notifications.ParseUtils$1
at notifications.ParseUtils.registerParse(ParseUtils.java:33)
Make sure, your NotificationUtils
calling or not .
Upvotes: 1