StaggeredGridView空指针

时间:2013-09-17 12:10:25

标签: android eclipse android-listview android-gridview

我刚刚将StaggeredView demo导入我的工作区,我在eclipse中没有错误,但是当我尝试启动演示时,我在logCat中遇到了这个错误:

09-17 14:01:06.111: E/AndroidRuntime(11611): FATAL EXCEPTION: main
09-17 14:01:06.111: E/AndroidRuntime(11611): java.lang.NullPointerException
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup$LayoutParams.<init>(ViewGroup.java:5299)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView$LayoutParams.<init>(StaggeredGridView.java:1768)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView.generateLayoutParams(StaggeredGridView.java:1657)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView.generateLayoutParams(StaggeredGridView.java:1)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.addViewInner(ViewGroup.java:3346)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.addViewInLayout(ViewGroup.java:3313)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.addViewInLayout(ViewGroup.java:3294)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView.fillDown(StaggeredGridView.java:1250)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView.populate(StaggeredGridView.java:844)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.support.v4.widget.StaggeredGridView.onLayout(StaggeredGridView.java:795)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.View.layout(View.java:11280)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.View.layout(View.java:11280)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.View.layout(View.java:11280)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.View.layout(View.java:11280)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.View.layout(View.java:11280)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1500)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2453)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.os.Looper.loop(Looper.java:137)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at android.app.ActivityThread.main(ActivityThread.java:4424)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at java.lang.reflect.Method.invokeNative(Native Method)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at java.lang.reflect.Method.invoke(Method.java:511)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-17 14:01:06.111: E/AndroidRuntime(11611):    at dalvik.system.NativeStart.main(Native Method)

有人能告诉我为什么会收到此错误吗?

1 个答案:

答案 0 :(得分:0)

问题出在错误的库中。您应该将this添加为项目库