Android: fix code error cause npe

This commit is contained in:
pengfei.zhou 2021-05-31 15:29:59 +08:00 committed by osborn
parent 783f77e7ac
commit b18bec6899

View File

@ -66,7 +66,7 @@ public class TextNode extends ViewNode<TextView> {
} }
JSValue maxHeight = jsObject.getProperty("maxHeight"); JSValue maxHeight = jsObject.getProperty("maxHeight");
if (maxHeight.isNumber()) { 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<TextView> {
return; return;
} }
String font = prop.asString().toString(); String font = prop.asString().toString();
String fontPath=""; String fontPath = "";
String fontName=font; String fontName = font;
if(font.contains("/")){ if (font.contains("/")) {
int separatorIndex=font.lastIndexOf("/"); int separatorIndex = font.lastIndexOf("/");
fontPath=font.substring(0,separatorIndex+1); fontPath = font.substring(0, separatorIndex + 1);
fontName=font.substring(separatorIndex+1); fontName = font.substring(separatorIndex + 1);
} }
if (fontName.endsWith(".ttf")) { if (fontName.endsWith(".ttf")) {
fontName = fontName.replace(".ttf",""); fontName = fontName.replace(".ttf", "");
} }
int resId = getContext().getResources().getIdentifier( int resId = getContext().getResources().getIdentifier(
@ -145,20 +145,20 @@ public class TextNode extends ViewNode<TextView> {
try { try {
Typeface iconFont = ResourcesCompat.getFont(getContext(), resId); Typeface iconFont = ResourcesCompat.getFont(getContext(), resId);
view.setTypeface(iconFont); view.setTypeface(iconFont);
}catch (Exception e){ } catch (Exception e) {
DoricLog.e("Error Font asset "+font+" in res/font"); DoricLog.e("Error Font asset " + font + " in res/font");
} }
} else { } else {
fontName = fontPath+ fontName = fontPath +
fontName + fontName +
".ttf"; ".ttf";
try { try {
Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), fontName); Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), fontName);
view.setTypeface(iconFont); view.setTypeface(iconFont);
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
DoricLog.e(font+" not found in Assets"); DoricLog.e(font + " not found in Assets");
} }
} }