在尝试使卡片翻转动画时继续获取空指针

时间:2013-07-10 21:19:58

标签: android eclipse animation

我想在Google智能手机列表视图动画https://github.com/nhaarman/ListViewAnimations

中点击一个项目(卡片)时翻卡

我正在使用示例Google卡片活动。当我点击它时,我试图让卡片翻转:http://bit.ly/1aaReU7 但我一直得到空指针异常。

你能告诉我最佳路线,以达到这个目的吗? 这是继续返回空指针异常的代码。 http://goo.gl/SYHQy

这是logcat错误:

07-10 17:02:26.032: D/AndroidRuntime(788): Shutting down VM
07-10 17:02:26.032: W/dalvikvm(788): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-10 17:02:26.187: E/AndroidRuntime(788): FATAL EXCEPTION: main
07-10 17:02:26.187: E/AndroidRuntime(788): java.lang.NullPointerException
07-10 17:02:26.187: E/AndroidRuntime(788):  at com.haarman.listviewanimations.GoogleCardsActivity$GoogleCardsAdapter.flipCard(GoogleCardsActivity.java:154)
07-10 17:02:26.187: E/AndroidRuntime(788):  at com.haarman.listviewanimations.GoogleCardsActivity$GoogleCardsAdapter.access$0(GoogleCardsActivity.java:143)
07-10 17:02:26.187: E/AndroidRuntime(788):  at com.haarman.listviewanimations.GoogleCardsActivity$GoogleCardsAdapter$2.onItemClick(GoogleCardsActivity.java:109)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2859)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.widget.AbsListView$1.run(AbsListView.java:3533)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.os.Handler.handleCallback(Handler.java:615)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.os.Looper.loop(Looper.java:137)
07-10 17:02:26.187: E/AndroidRuntime(788):  at android.app.ActivityThread.main(ActivityThread.java:4745)
07-10 17:02:26.187: E/AndroidRuntime(788):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 17:02:26.187: E/AndroidRuntime(788):  at java.lang.reflect.Method.invoke(Method.java:511)
07-10 17:02:26.187: E/AndroidRuntime(788):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-10 17:02:26.187: E/AndroidRuntime(788):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-10 17:02:26.187: E/AndroidRuntime(788):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

View rootLayout = (View) findViewById(R.layout.activity_googlecards);

这不会返回视图。这就是崩溃的原因。

我建议在activity_googlecards.xml布局中为您的根视图提供一个id,然后获取一个引用,如下例所示:

View rootLayout = (View) findViewById(R.id.root_view);