[英]NoClassDefFound in NotificationCompat.Builder
這個概念是在特定時間獲得通知。 顯然,我做到了,直到我將支持版本低於HoneyComb
及其之上。
我已經設置了最低版本的SDK 8和目標SDK 17.由於類編碼要大得多,我只顯示存在問題的核心區域:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, TaskDetails.class), 0);
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, text, time);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(text).setWhen(time)
.setAutoCancel(true).setContentTitle(title)
.setContentText(text).build();
mNM.notify(NOTIFICATION, notification);
}
問題是,
Notification.Builder
。 Notification.Builder
具有包含在API級別11中的方法(因此在"Call requires API level 11 or more"
顯示錯誤)。 NotificationCompat.Builder
的解決方案。 最后,到達沒有發現錯誤的階段,我在Sony Xperia Tipo Dual ST21i2上運行我的項目...
悲劇結局:我收到以下錯誤日志:
06-01 06:34:14.199: E/AndroidRuntime(4178): FATAL EXCEPTION: main
06-01 06:34:14.199: E/AndroidRuntime(4178): java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder
06-01 06:34:14.199: E/AndroidRuntime(4178): at com.todotaskmanager.service.NotifyService.showNotification(NotifyService.java:99)
06-01 06:34:14.199: E/AndroidRuntime(4178): at com.todotaskmanager.service.NotifyService.onStartCommand(NotifyService.java:68)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.access$1900(ActivityThread.java:123)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.os.Looper.loop(Looper.java:137)
06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-01 06:34:14.199: E/AndroidRuntime(4178): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 06:34:14.199: E/AndroidRuntime(4178): at java.lang.reflect.Method.invoke(Method.java:511)
06-01 06:34:14.199: E/AndroidRuntime(4178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
06-01 06:34:14.199: E/AndroidRuntime(4178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-01 06:34:14.199: E/AndroidRuntime(4178): at dalvik.system.NativeStart.main(Native Method)
好的......我解決了我的問題。
右鍵單擊項目goto屬性 - > Java Build Path。 選擇訂單導出選項卡。 確保選中了Android私有庫。 如果您已引用庫項目。 同樣為圖書館項目做同樣的事情。 清潔和建設。
也轉到android sdk管理器並檢查你是否安裝了android sdk構建工具。 這可能沒有必要,但要確保安裝了android構建工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.