为了账号安全,请及时绑定邮箱和手机立即绑定

​java.lang.NullPointerException: Cannot invoke "Humen.humen.hoHome()" because "zhangsan" is null为啥出现这个问题

Humen;

com.example.demo2.Car.Car;

ZhangSan HumenWithCar{
    (Car car){
        (car);
    }

    (){
        .start();
        .turnLeft();
        .turnRight();
        .stop();
    }
}


Humen;

com.example.demo2.Car.Car;

LiSi HumenWithCar{
    (Car car){
        (car);
    }

    (){
        .start();
        .turnRight();
        .stop();
    }
}


com.example.demo2.Car;
java.lang.reflect.Constructor;
java.lang.reflect.InvocationTargetException;
java.util.Map;
java.util.concurrent.ConcurrentHashMap;

IoCContainer {
    Map<String, Object> = ConcurrentHashMap<String, Object>();

    Object (String beanId) {
        .get(beanId);
    }

    (Class<?> clazz, String beanId, String ...paramBeanIds) {
        Object[] paramValues = Object[paramBeanIds.];

        (i = ; i < paramBeanIds.; i++) {
            paramValues[i] = .get(paramBeanIds[i]);
        }
        Object bean = ;
        (Constructor<?> constructor : clazz.getConstructors()) {
            {
                bean = constructor.newInstance(paramValues);
            } (InstantiationException | InvocationTargetException | IllegalAccessException e) {
            }
        }
        (bean==) {
            RuntimeException();
        }

        .put(beanId, bean);
    }
}
com.example.demo2;


Humen.LiSi;
Humen.ZhangSan;
Humen.humen;
com.example.demo2.Car.Audi;
com.example.demo2.Car.Buick;
com.example.demo2.Car.IoCContainer;
org.junit.;
org.junit.jupiter.api.;



Demo2ApplicationTests {
    IoCContainer = IoCContainer();

    (){
        .setBeans(Audi., );
        .setBeans(Buick., );
        .setBeans(ZhangSan., ,);
        .setBeans(LiSi., ,);

    }
    () {
         humen zhangsan = (humen) .getBean();
         zhangsan.hoHome();

        humen lisi = (humen) .getBean();
        lisi.hoHome();
    }

}


java.lang.NullPointerException: Cannot invoke "Humen.humen.hoHome()" because "zhangsan" is null

正在回答

1 回答

humen这个类名首字母要大写

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

​java.lang.NullPointerException: Cannot invoke "Humen.humen.hoHome()" because "zhangsan" is null为啥出现这个问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信