1
我在Android應用中遇到問題,我的活動實施CreateNdefMessageCallback
,它在API 14+
中可用。Android使用TargetApi實現接口
我註明了實施方法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
目前,我做了一個內部的Annonymous Inner Type,但是如果你有其他的解決方案,我會試試! – Gaetan