Attempt to invoke virtual method ‘char[] java.lang.String.toCharArray()‘ on a null object reference

1. If the error message is as follows.

E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler
    java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
        at java.math.BigDecimal.<init>(BigDecimal.java:425)
        at com.example.centralcontrol.activity.pnManager.view.ll_table.add(ll_table.java:166)
        at com.example.centralcontrol.activity.pnManager.view.ll_table.initMapView(ll_table.java:109)
        at com.example.centralcontrol.activity.pnManager.view.ll_table.<init>(ll_table.java:61)
        at com.example.centralcontrol.activity.pnManager.PnManagerActivity.lambda$initViewModel$3$com-example-centralcontrol-activity-pnManager-PnManagerActivity(PnManagerActivity.java:93)

2. You can see if the object is empty.
my project is empty here

String total="55";
String value=null;
new BigDecimal(total).add(new BigDecimal(value)).toString();
//当程序运行到这里的时候,就会崩溃,因为value的值为空,没有创建这个变量

3. After we assign a value to value, this error message will not appear again

Guess you like

Origin blog.csdn.net/qq_36570506/article/details/130226891