【问题标题】:Android application crash on notificationAndroid 应用程序在通知时崩溃
【发布时间】:2015-07-29 17:47:55
【问题描述】:

我正在尝试学习使用本教程在 Android 中创建通知:

http://www.androidbegin.com/tutorial/android-custom-notification-tutorial/

应用程序将在我的手机上编译和运行,但是当我按下按钮显示通知时它崩溃了。

我在日志中发现了这个错误:

找不到类 'android.support.v4.app.NotificationCompat$Builder',引用自方法 com.androidbegin.notificationtutorial.MainActivity.notification

我找到的解决方案是确保在项目属性的“订单和导出”选项卡上检查了正确的条目,然后清理项目。我曾尝试检查各种组合的项目,但没有任何效果。我相信当我第一次创建项目时,Android Private LibrariesAndroid Dependencies 已检查(android-support-v4.jar 已列出,但未检查)。

还有什么我可能遗漏的吗?

编辑:这是来自此应用程序的 logcat:

07-29 12:30:45.776: E/dalvikvm(24133): Could not find class 'android.support.v4.app.NotificationCompat$Builder', referenced from method com.androidbegin.notificationtutorial.MainActivity.notification
07-29 12:30:45.776: W/dalvikvm(24133): VFY: unable to resolve new-instance 7 (Landroid/support/v4/app/NotificationCompat$Builder;) in Lcom/androidbegin/notificationtutorial/MainActivity;
07-29 12:30:46.026: I/Adreno-EGL(24133): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_KK_2.7_RB1.04.04.02.007.045_msm8960_KK_2.7_RB1__release_AU ()
07-29 12:30:46.026: I/Adreno-EGL(24133): OpenGL ES Shader Compiler Version: 17.01.12.SPL
07-29 12:30:46.026: I/Adreno-EGL(24133): Build Date: 03/13/14 Thu
07-29 12:30:46.026: I/Adreno-EGL(24133): Local Branch: 
07-29 12:30:46.026: I/Adreno-EGL(24133): Remote Branch: quic/kk_2.7_rb1.31
07-29 12:30:46.026: I/Adreno-EGL(24133): Local Patches: NONE
07-29 12:30:46.026: I/Adreno-EGL(24133): Reconstruct Branch: AU_LINUX_ANDROID_KK_2.7_RB1.04.04.02.007.045 +  NOTHING
07-29 12:30:51.692: W/dalvikvm(24133): threadid=1: thread exiting with uncaught exception (group=0x4161de18)
07-29 12:30:51.702: E/AndroidRuntime(24133): FATAL EXCEPTION: main
07-29 12:30:51.702: E/AndroidRuntime(24133): Process: com.androidbegin.notificationtutorial, PID: 24133
07-29 12:30:51.702: E/AndroidRuntime(24133): java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder
07-29 12:30:51.702: E/AndroidRuntime(24133):    at com.androidbegin.notificationtutorial.MainActivity.notification(MainActivity.java:60)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at com.androidbegin.notificationtutorial.MainActivity$1.onClick(MainActivity.java:33)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.view.View.performClick(View.java:4480)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.view.View$PerformClick.run(View.java:18673)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.os.Handler.handleCallback(Handler.java:733)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.os.Handler.dispatchMessage(Handler.java:95)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.os.Looper.loop(Looper.java:157)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at android.app.ActivityThread.main(ActivityThread.java:5872)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at java.lang.reflect.Method.invokeNative(Native Method)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at java.lang.reflect.Method.invoke(Method.java:515)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
07-29 12:30:51.702: E/AndroidRuntime(24133):    at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

  • 你能发布你的 Logcat 吗?
  • 检查支持库,然后尝试
  • 您应该将android-support-v4.jar 添加到您的构建路径并构建到您的应用中。

标签: android noclassdeffounderror


【解决方案1】:

现在可以了!

我尝试在 Order and Export 选项卡中检查 android-support-v4.jar 并清理了项目,现在我的应用程序可以显示通知了。

我很确定我在发布此问题之前尝试过此操作,但当时没有成功。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-21
    • 1970-01-01
    相关资源
    最近更新 更多