大佬教程收集整理的这篇文章主要介绍了android – NullPointerException在TextView.checkForRelayout(),而setText(),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// Now we create label view and convert it into bitmap private Bitmap createLabelBitmap(GisLaborHistoryObject object,HistoryPoint point) { // create view from xml if (vh == null) { vh = new ViewHolder(); vh.view = inflater.inflate(R.layout.map_gis_history_label,null,falsE); vh.tv = (TextView) vh.view.findViewById(R.id.gislabeltext); } // set label content if (vh.tv != null) { if (!mSingleLaborHistory) { String name = ""; name = object.getDisplayName(); if (name == null || "".equals(Name)) name = object.getPersonId(); if (name == null || "".equals(Name)) name = object.getLaborCode(); if (name == null) name = ""; vh.tv.setText(Name); } else vh.tv.setText(point.getChangeDate()); } // measure resulTing view vh.view.measure(spec,spec); vh.view.layout(0,vh.view.getMeasuredWidth(),vh.view.getMeasuredHeight()); Bitmap b = Bitmap.createBitmap(vh.view.getWidth(),vh.view.getHeight(),Bitmap.Config.ARGB_8888); canvasToDraw.setBitmap(b); canvasToDraw.translate(-vh.view.getScrollX(),-vh.view.getScrollY()); vh.view.draw(canvasToDraw); return b; }
规格是
spec = MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED);
结果是
logcat的:
04-29 17:12:34.057: E/AndroidRuntime(389): java.lang.NullPointerException 04-29 17:12:34.057: E/AndroidRuntime(389): at android.widget.TextView.checkForRelayout(TextView.java:5497) 04-29 17:12:34.057: E/AndroidRuntime(389): at android.widget.TextView.setText(TextView.java:2730) 04-29 17:12:34.057: E/AndroidRuntime(389): at android.widget.TextView.setText(TextView.java:2598) 04-29 17:12:34.057: E/AndroidRuntime(389): at android.widget.TextView.setText(TextView.java:2573) 04-29 17:12:34.057: E/AndroidRuntime(389): at com.xxx.android.proj.ui.map.overlays.LaborsmarkerOverlay.createLabelBitmap(LaborsmarkerOverlay.java:164)
我使用的XML布局
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://scheR_230_11845@as.android.com/apk/res/android" android:id="@+id/gislabeltext" style="@style/labelStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="2dp" android:paddingRight="2dp" />
可能是这个错误的原因?
vh.tv = (TextView) vh.view.findViewById(R.id.gislabeltext); vh.tv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
我的错误是,当使用ViewGroup膨胀时,我必须显式设置LayoutParams root = null;一切正常,直到我尝试重用TextView乘法时间.
以上是大佬教程为你收集整理的android – NullPointerException在TextView.checkForRelayout(),而setText()全部内容,希望文章能够帮你解决android – NullPointerException在TextView.checkForRelayout(),而setText()所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。