Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

绘制背景报空指针异常 #90

Open
swnnn opened this issue Dec 5, 2017 · 4 comments
Open

绘制背景报空指针异常 #90

swnnn opened this issue Dec 5, 2017 · 4 comments

Comments

@swnnn
Copy link

swnnn commented Dec 5, 2017

1.问题描述:执行BackgroundCountDown的onDraw方法canvas.drawRoundRect绘制圆角背景时,报java.lang.NullPointerException: Attempt to read from field 'float android.graphics.RectF.left' on a null object reference
2.由于是线上问题,且没有有效的mapping文件,所以并不能定位复现该问题,问题出现在4.4、5.0、6.0
、7.0等机型上,覆盖面比较广
3.通过阅读源代码,并不能找到手动把mHourBgBorderRectF、mHourBgRectF等变量置为null的逻辑
4.附上布局文件如下:
<xxx.countdownview.CountdownView
android:id="@+id/hc_recommend_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
app:isHideTimeBackground="false"
app:isShowDay="false"
app:isShowHour="true"
app:isShowMillisecond="false"
app:isShowMinute="true"
app:isShowSecond="true"
app:isShowTimeBgDivisionLine="false"
app:suffix=":"
app:suffixHourRightMargin="2dp"
app:suffixMinuteRightMargin="2dp"
app:isTimeTextBold="true"
app:isSuffixTextBold="true"
app:suffixLRMargin="1dp"
app:suffixGravity="center"
app:suffixTextColor="#ffa14d"
app:suffixTextSize="14sp"
app:timeBgColor="#FFa14d"
app:timeTextColor="#FFFFFF"
app:timeBgSize="20dp"
app:timeBgRadius="4dp"
app:timeTextSize="14sp" />

@yudapiandroid
Copy link

错误是在绘制背景的时候出现的~
据说是硬件加速的问题~
关闭硬件加速,尝试了几种办法都没解决~
我这边是测试到了 4.x 的时候有问题。
做了两种情况:
1、4.x 不绘制背景 5.x 绘制背景
2、绘制的时候try
@OverRide
protected void onDraw(Canvas canvas) {
setLayerType(View.LAYER_TYPE_SOFTWARE,null);
try {
super.onDraw(canvas);
}catch (Exception e){
DynamicConfig.Builder builder = new DynamicConfig.Builder();
builder.setBackgroundInfo(null);
dynamicShow(builder.build());
super.onDraw(canvas);
}
}

@swnnn
Copy link
Author

swnnn commented Dec 7, 2017

我查看了下我们的工程配置,发现没有主动开启硬件加速功能,所以他应该是默认关闭的,请问下,您是怎么测试能出现这个问题呢,能把报错的日志粘贴出来吗,我在测试的时候一直没有出现这个问题~~

@swnnn
Copy link
Author

swnnn commented Dec 7, 2017

然后我发现有个问题,首次初始化CountDownView的时候,会调用多次BackgroundCountDown的onMeasure()方法,就会执行多次initTimeBgRect()方法,在该方法中就会创建多个rectf对象,这个地方有没有可能有问题呢

@chemin233
Copy link

chemin233 commented Jun 25, 2018

首次进入这个页面没有问题,但是第二次进入这个页面就会报这个错,魅族 note6

[message]: Attempt to read from field 'float android.graphics.RectF.left' on a null object reference;
[LocalizedMessage]: Attempt to read from field 'float android.graphics.RectF.left' on a null object reference;
[stacktrace]: java.lang.NullPointerException: Attempt to read from field 'float android.graphics.RectF.left' on a null object reference
at android.graphics.Canvas.drawRoundRect(Canvas.java:1400)
at cn.iwgang.countdownview.BackgroundCountdown.onDraw(BackgroundCountdown.java:321)
at cn.iwgang.countdownview.CountdownView.onDraw(CountdownView.java:91)
at android.view.View.draw(View.java:17304)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.draw(View.java:17307)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4400)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.draw(View.java:17307)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3792)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.draw(View.java:17307)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.draw(View.java:17307)
at com.android.internal.policy.DecorView.draw(DecorView.java:789)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2835)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2637)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2241)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1276)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6477)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:888)
at android.view.Choreograph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants