From b18bec6899532757efdd1138f71458aea01e1b85 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 31 May 2021 15:29:59 +0800 Subject: [PATCH] Android: fix code error cause npe --- .../main/java/pub/doric/shader/TextNode.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java b/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java index 479f980d..1d18bb1b 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/TextNode.java @@ -66,7 +66,7 @@ public class TextNode extends ViewNode { } JSValue maxHeight = jsObject.getProperty("maxHeight"); if (maxHeight.isNumber()) { - mView.setMaxHeight(DoricUtils.dp2px(maxWidth.asNumber().toFloat())); + mView.setMaxHeight(DoricUtils.dp2px(maxHeight.asNumber().toFloat())); } } @@ -125,16 +125,16 @@ public class TextNode extends ViewNode { return; } String font = prop.asString().toString(); - String fontPath=""; - String fontName=font; - if(font.contains("/")){ - int separatorIndex=font.lastIndexOf("/"); - fontPath=font.substring(0,separatorIndex+1); - fontName=font.substring(separatorIndex+1); + String fontPath = ""; + String fontName = font; + if (font.contains("/")) { + int separatorIndex = font.lastIndexOf("/"); + fontPath = font.substring(0, separatorIndex + 1); + fontName = font.substring(separatorIndex + 1); } if (fontName.endsWith(".ttf")) { - fontName = fontName.replace(".ttf",""); + fontName = fontName.replace(".ttf", ""); } int resId = getContext().getResources().getIdentifier( @@ -145,20 +145,20 @@ public class TextNode extends ViewNode { try { Typeface iconFont = ResourcesCompat.getFont(getContext(), resId); view.setTypeface(iconFont); - }catch (Exception e){ - DoricLog.e("Error Font asset "+font+" in res/font"); + } catch (Exception e) { + DoricLog.e("Error Font asset " + font + " in res/font"); } } else { - fontName = fontPath+ + fontName = fontPath + fontName + ".ttf"; try { Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), fontName); view.setTypeface(iconFont); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - DoricLog.e(font+" not found in Assets"); + DoricLog.e(font + " not found in Assets"); } }