问题描述
- java.lang.NullPointerException 在学习armenu时候遇到这问题的
- java.lang.NullPointerException
at com.administrator_example.icm_arcmenu.view.ArcMenu.layoutButton(ArcMenu.java:137) 这句:mCButton.setOnClickListener(this);
at com.administrator_example.icm_arcmenu.view.ArcMenu.onLayout(ArcMenu.java:129)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1717)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1571)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1480)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14841)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1986)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1743)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5603)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)private void layoutButton() { mCButton = getChildAt(0); mCButton.setOnClickListener(this); int l = 0;//子布局左边界与父布局左边界的距离 int t = 0;//子布局上边界与上边界的距离 r:子布局右边界与父布局左边界的距离 b:子布下边界与父布局上边界 int width = mCButton.getMeasuredWidth(); //子布局宽度 int height = mCButton.getMeasuredHeight(); switch (mpostion) { case LEFT_TOP: l = 0; t = 0; break; case LEFT_BOTTOM: l=0; t=getMeasuredHeight()-height; break; case RIGHT_TOP: l = getMeasuredWidth()-width; t = 0; break; case RIGHT_BOTTOM: l = getMeasuredWidth()-width; t = getMeasuredHeight()-height; break; } mCButton.layout(ltl+widtht+height);
解决方案
你这个是子布局?将this换成XXX.class试试。
解决方案二:
看看是哪个对象为null了,所以报错
时间: 2024-11-02 23:38:07