简体   繁体   中英

convert Integer to int

I have an Integer value of variable as below:

Integer programNumber= ........

I took the program number as Integer type. However in my other class, I want to check whether this variable, programNumber, equals variable which is the type of int.

To sum up, I want to convert the variable of the of Integer to int primitive value. I used programno.intValue() but it doesn't work. Thanks in advance.

I have a two class, BasvuruKisi and Program. the code snippet is below:

BasvuruKisi bsvkisi = (BasvuruKisi) (this.getHibernateTemplate().find("from BasvuruKisi bsv where bsv.basvuruNo=?", basvuruNumaralari.get(i))).get(0);

        if (bsvkisi != null) {
            int yetkiVarmi = 0;
            Integer programno= bsvkisi.getProgramId();
           List array = 

this.getHibernateTemplate().find("from Program p where p.id=?", programno.intValue());

but

this.getHibernateTemplate().find("from Program p where p.id=?", programno.intValue());

this one doesn't work. return firstly, no table or view is available despite available and then returns null pointer exception. thanks

The variable name in the initialization block says programNumber, but the variable in the method call is programno. Which is it?

Using the wrong variable name shouldn't give you a null pointer exception, unless you have another variable named programno defined somewhere.

Whatever the variable name is, make sure you initialize it before you get the intValue.

Validate programNumber is null or not?

If the value is null, it throws Exception.

Integer programNumber= null;
System.out.println(programNumber.intValue());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM