我在 Android 应用程序中遇到问题,我的活动实现CreateNdefMessageCallback
了API 14+
.
public NdefMessage createNdefMessage(NfcEvent event)
我用.注释了实现的方法@TargetApi(14)
。它在 Android 4 设备上运行良好,但在低于 Android 4.0 的设备上加载时会崩溃!
唯一的解决方案是为实现创建另一个class
?或者有可能有一个有条件的实现@TargetApi
?
这是完整的例外,如果我删除它不会附加implements CreateNdefMessageCallback
:
04-15 11:22:28.063: E/AndroidRuntime(3784): FATAL EXCEPTION: main
04-15 11:22:28.063: E/AndroidRuntime(3784): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{XXXX/XXXX.MyActivity}: java.lang.ClassNotFoundException: XXXX.MyActivity in loader dalvik.system.PathClassLoader[/data/app/XXXX.apk]
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.os.Looper.loop(Looper.java:123)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-15 11:22:28.063: E/AndroidRuntime(3784): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 11:22:28.063: E/AndroidRuntime(3784): at java.lang.reflect.Method.invoke(Method.java:521)
04-15 11:22:28.063: E/AndroidRuntime(3784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 11:22:28.063: E/AndroidRuntime(3784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 11:22:28.063: E/AndroidRuntime(3784): at dalvik.system.NativeStart.main(Native Method)
04-15 11:22:28.063: E/AndroidRuntime(3784): Caused by: java.lang.ClassNotFoundException: XXXX.MyActivity in loader dalvik.system.PathClassLoader[/data/app/XXXX.apk]
04-15 11:22:28.063: E/AndroidRuntime(3784): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-15 11:22:28.063: E/AndroidRuntime(3784): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-15 11:22:28.063: E/AndroidRuntime(3784): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-15 11:22:28.063: E/AndroidRuntime(3784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-15 11:22:28.063: E/AndroidRuntime(3784): ... 11 more