0

当在谷歌卡片列表视图动画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)
4

1 回答 1

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

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

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

View rootLayout = (View) findViewById(R.id.root_view);
于 2013-07-10T21:57:35.143 回答